While this is a viable way to do it, you don't have to use jobs at all. Get-WMIObject
takes a String[]
for the ComputerName
parameter, and if multiple computernames are passed, it will poll multiple machines simultaneously (I think up to 32, but I don't recall exactly) & return an extra field in the results, PSComputerName
You can do this much more simply.
$servernames = @();
$servernames += get-qadcomputer -searchroot $ou|select name|%{if(test-connection -quiet $_.name) {$_.name}}
get-wmiobject -computername $servernames win32_operatingsystem|select PSComputername,LastBootTime
then calculate your uptime from there for each computer.
Edit (Kayasax) : here is the final recipe :
$alive=@()
$obj=@()
Get-QADComputer -SearchRoot $ou -SizeLimit 4000 |select -ExpandProperty name |foreach-object {
if (Test-Connection -Quiet -count 1 $_){ $alive+=$_ }
}
Get-wmiobject -computername $alive -Class Win32_OperatingSystem |select PSComputerName, lastBootUpTime |foreach-object{
$sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($_.lastBootUpTime)
$props=@{"name"=$_.PSComputername;"uptime"=$sysuptime.days}
$obj+= new-Object -TypeName PSCustomObject -property $props
}
$obj |sort-object uptime -desc