# Create a file for output
$file=”C:\Greyagents.txt”
$startdate =Get-date
$runtime =”$(Get-date -format “M/dd/yyyy H:MM”)”
$CurrentDate = $CurrentDate.ToString(‘MM-dd-yyyy_hh-mm-Ss’)
#get the SystemCenter Agent Class
$agent = Get-SCOMClass | where-object{$_.name -eq “microsoft.systemcenter.agent”}
#Get the grey agents
$objects = Get-SCOMMonitoringObject -class:$agent | where {$_.IsAvailable –eq $false}
forEach($object in $objects)
{
# display list of grey agents in PS window
write-host “Greyagents:$object”
#if you want output to Notepad, execute this
$object.displayname+”,”+$Object.HealthState| Out-file $file -append
# if you want output to csv, execute this
$object|Select Displayname,Healthstate | Export-Csv -Path “C:\Greyagents\Greyagents_$currentdate.csv”
}
Thanks for the script.
this script output gives some uninitialized servers as well..but not complete list of servers with uninitialized state.
could you please suggest.
LikeLike