$scriptBlock={
$wmi = Get-WmiObject -Class Win32_OperatingSystem
($wmi.ConvertToDateTime($wmi.LocalDateTime) – $wmi.ConvertToDateTime($wmi.LastBootUpTime)).TotalHours
}
$UpTime = @()
Import-Module ActiveDirectory
Get-ADComputer -Filter 'ObjectClass -eq "Computer"' -SearchBase "OU=someOu,DC=someDomain,DC=someTld" -SearchScope Subtree `
| % { $Uptime += `
(New-Object psobject -Property @{
"ComputerName" = $_.DNSHostName
"UpTimeHours" = (Invoke-Command -ComputerName $_.DNSHostName -ScriptBlock $scriptBlock)
}
)
}
$UpTime | Where-Object {$_.UpTimeHours -ne ""} | sort-object -property @{Expression="UpTimeHours";Descending=$false} | `
Select-Object -Property ComputerName,@{Name="UpTimeHours"; Expression = {$_.UpTimeHours.ToString("#.##")}} | `
Format-Table -AutoSize