Get Microsoft Monitoring Agent settings remotely

http://www.powershellbros.com/get-microsoft-monitoring-agent-settings-remotely/

 

To find Agent Management Groups we need to run this command – in my case path was:

HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\

(Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\")

Usage:

Get-MMAgent -Computername DC01
Get-MMAgent -Computername DC01 -Verbose
Get-MMAgent -Computername DC01,DCO2,DC03 | Out-GridView
Get-MMAgent -Computername DC01,DCO2,DC03 | Format-Table
Get-MMAgent -Computername (Get-Content "c:\temp\servers.txt")
Get-MMAgent -Computername (gc "c:\temp\servers.txt") -Verbose | Format-Table
Get-MMAgent -Computername DC01,DCO2,DC03 | Export-Csv -Path C:\users\$env:username\desktop\results.csv -NoTypeInformation

Output:

Get-MMAgent

 

Final script:

Function Get-MMAgent {
    [CmdletBinding()]
                
    # Parameters used in this function
    Param
    (
        [Parameter(Position=0, Mandatory = $True, HelpMessage="Provide server names", ValueFromPipeline = $true)]
        $Computername
    )
      
    $Results = @()
    #$Credentials = Get-Credential "domain\pawel.janowicz"
    ForEach($Server in $Computername)
    {
        Write-Verbose "Processing $server"
    
        Try
        {
            $SCOMGroups = Invoke-Command -Computername $Server -ErrorAction Stop -ScriptBlock { (Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\") } #-Credential $CRED
        }
        Catch
        {
            $_.Exception.Message
            Continue
        }      
        If(!$SCOMGroups)
        {
            Write-Warning "No SCOM groups have been found"
        }
        Else
        {
            ForEach($item in $SCOMGroups)
            {
                $Path = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\" + $item.PSChildName + "\Parent Health Services\0"
            
                Try
                {
                    $reg = Invoke-Command -Computername $Server -ErrorAction Stop -ScriptBlock {param($Path) (Get-ItemProperty $Path) }  -ArgumentList $Path #-Credential $Cred
                }
                Catch
                {
                    $_.Exception.Message
                    Continue
                }
                If($Reg)
                {
                    $Status = (Get-Service -ComputerName $Server -name HealthService).status
                    $Object = New-Object PSObject -Property ([ordered]@{
   
                        Server                  = $Server
                        HealthService           = $Status
                        SCOMGroup               = $item.PSChildName
                        MgmtServer              = $reg.AuthenticationName
                        Port                    = $reg.Port
  
                    })
    
                    $Results += $Object
                }
            }       
        }
    }
    If($Results)
    {
        Return $Results
    }
}
Advertisements

Author: scomengineer

Raj Penukonda as software engineer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s