search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Windows Server Uptime Check Script after Patch Restarts
Posted in Windows Powershell, Windows Server | No Comment | 12,362 views | 17/08/2013 22:41

This is pretty cool script after patch updates to check which servers are successfully rebooted.

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
}

I hope that helps :)



Leave a Reply