Powershell - Report Windows Uptime

List this:
$servers=("Server1","Server2","Server3","Server4", `
 "Server5","Server6","Server7","Server8")
Run this:
Function ServerBootTime
{
 [CmdletBinding()]
 param($server)
 return (
  $wmi=Get-WmiObject Win32_OperatingSystem -ComputerName $server | `
   Select `
   @{Name="System Name"; `
    Expression={($Computerobj.ComputerName = $server)}}, `
   @{Name="Uptime"; `   
    Expression={$ts=((Get-Date)-($_.ConvertToDateTime($_.LastBootUpTime))); `
     "{0:000} days {1:00} hours {2:00} minutes {3:00} seconds" `
     -f ($ts.Days),$ts.Hours,$ts.Minutes,$ts.Seconds}},
   @{Name="Last Reboot"; `
    Expression={($_.ConvertToDateTime($_.LastBootUpTime))}}
 )
}

$serverboot = foreach ($server in $servers)
{
 ServerBootTime $server
}
$serverboot | Out-GridView -Title "Boot Time"
View this:

No comments:

Post a Comment