Get health service IDs from file

This reads in a list of computer names and gets the health service ID for each one and writes the output to screen and file.

[int]$count="" # need to declare or $count gets weird.
$fqdn=""
$file=""
$file+="FQDN,ID`r"
$a=gc C:\temp\file.txt | sort
$output="c:\temp\HealthServiceIDs.csv"
foreach ($i in $a) {
$b=Get-SCOMClass -Name Microsoft.SystemCenter.HealthService | Get-SCOMClassInstance | where {$_.displayname -eq $i}
$fqdn=$b.displayname
$id=$b.id
write-host "$fqdn, $id"
$file+="$fqdn,$id`r"
}
write-host "Exporting output to $output"
$file | out-file $output

Comments