NewRelicPS.Agents.psm1

<#
.Synopsis
    Confirms the user is running as an admin in an elevated session.
.Description
    Confirms the user is running as an admin in an elevated session. If not throws an error.
.Example
    Confirm-RunAsAdmin
#>

Function Confirm-RunAsAdmin {
    [CMDLetBinding()]
    [OutputType([System.Boolean])]
    Param (
    )
    if([bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")){
        return $true
    }else{
        Throw "You must run this as an admin and in an elevated session to proceed."
    }
}

<#
.Synopsis
    Combines 2 HashTables into one HashTable
.Description
    Combines 2 HashTables into one HashTable. If they have duplicate keys the override value will be used.
.Example
    Join-HashTable -Base $Hash -Override $Hash2
#>

Function Join-HashTable {
    [CMDLetBinding()]
    [OutputType([System.Collections.Hashtable])]
    Param (
        [Parameter (Mandatory = $true)]
        [Hashtable] $Base,
        [Parameter (Mandatory = $true)]
        [Hashtable] $Override
    )

    # Copy keys into new hash not to modify the original
    $returnHash = @{}
    foreach ($key in $Base.Keys) {
        $returnHash.Add($key, $Base[$key])
    }

    foreach ($key in $Override.Keys) {
        if($null -eq $returnHash[$key]){
            Write-Verbose "Adding settings $key"
            $returnHash.Add($key, $Override[$key])
        }else{
            if($returnHash[$key] -ne $Override[$key]){
                Write-Verbose "Updating setting $key"
                $returnHash[$key] = $Override[$key]
            }
        }
    }

    return $returnHash
}