# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 4.1 # # NAME: Display-NetAgentsByHostName.ps1 # # AUTHOR: Jeremy D. Pavleck , JPavleck@GMail.com # DATE : 6/5/2008 # # COMMENT: A simple function that increases the information of your SCOM command shell. This one # returns the hostnames of the managed devices as well as color coding them based on Health State. # # ============================================================================================== function Display-NetAgentsByHostName([switch]$short) { function LookUp([string]$ip) { trap { "Unable to resolve IP" continue; } ([System.Net.Dns]::GetHostByAddress($ip)).HostName } Get-RemotelyManagedDevice | ForEach-Object { If (!$short) { If ($_.HealthState -eq "Success") { Write-Host ("IP Address $($_.Name) resolves to '$(Lookup($_.Name))' - Managed by server: $($_.ProxyAgentPrincipalName.Split('.;')[0])" + "in Management group: $($_.ManagementGroup) - Health State: $($_.HealthState)`n") -ForeGroundColor Green } elseif ($_.HealthState -eq "Warning") { Write-Host ("IP Address $($_.Name) resolves to '$(Lookup($_.Name))' - Managed by server: $($_.ProxyAgentPrincipalName.Split('.;')[0])" + "in Management group: $($_.ManagementGroup) - Health State: $($_.HealthState)`n") -ForeGroundColor Yellow } elseif ($_.HealthSTate -eq "Error") { Write-Host ("IP Address $($_.Name) resolves to '$(Lookup($_.Name))' - Managed by server: $($_.ProxyAgentPrincipalName.Split('.;')[0])" + "in Management group: $($_.ManagementGroup) - Health State: $($_.HealthState)`n") -ForeGroundColor Red } } else { If ($_.HealthState -eq "Success") { Write-Host "HEALTHY - Host: $(Lookup($_.Name)) - IP: $($_.Name)" -ForeGroundColor Green } elseif ($_.HealthState -eq "Warning") { Write-Host "HEALTH WARNING! State: $($_.HealthState) - Host: $(Lookup($_.Name)) - IP: $($_.Name)" -ForeGroundColor Yellow } elseif ($_.HealthState -eq "Error") { Write-Host "HEALTH ERROR! State: $($_.HealthState) - Host: $(Lookup($_.Name)) - IP: $($_.Name)" -ForeGroundColor Red } } } }