Get Microsoft Monitoring Agent settings remotely

Today I want to show you how to get Microsoft Monitoring Agent settings remotely using PowerShell function. This might be useful when you need to scan all servers in large scale environment to determine that configuration has been set properly.

The Microsoft Monitoring Agent

The Microsoft Monitoring Agent is a service used to watch and report on application and system health on a Windows computer. The Microsoft Monitoring Agent collects and reports a variety of data including performance metrics, event logs and trace information.

Microsoft Monitoring Agent
Microsoft Monitoring Agent

In previous post I described how to get all unhealthy SCOM agents – link. Script checked agent state and its primary management server. This time script gathers information about agent properties from registry.

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
Get-MMAgent

You can compare if results are the same as those in SCOM Operations Console. There might a situation that server is reporting to wrong management server and in scom console it is shown as unhealthy.

To check it you have to run this script – link or go to administration tab to Agent Managed section:

scom console
scom console

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
    }
}

One thought on “Get Microsoft Monitoring Agent settings remotely

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.