1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| $Servers = Get-Content C:\UpdateServers.txt
function WMIDateStringToDate($Bootup) {
[System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup)
}
foreach ($Server in $Servers)
{
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $Server
$Bootup = $OS.LastBootUpTime
$LastBootUpTime = WMIDateStringToDate($Bootup)
$Now = Get-Date
$Uptime = $Now - $LastBootUpTime
$d = $Uptime.Days
$h = $Uptime.Hours
$m = $uptime.Minutes
$ms= $uptime.Milliseconds
$a = "$Server Up for: {0} days, {1} hours, {2}.{3} minutes" -f $d,$h,$m,$ms
Write-Host "$a" -ForegroundColor Green
} |