Servers Monthly uptime report Script
#To Obtain uptime report of the VMs. You need to create
and update the list of Server name sin List.txt file on C:\temp
$servers = Get-Content C:\temp\List.txt
foreach ($s in $servers)
{
try
{
$a=Get-WmiObject -ComputerName $s
-Class Win32_OperatingSystem -ErrorAction ‘Stop’
$b =
$a.convertToDateTime($a.Lastbootuptime)
[TimeSpan]$LastBoot = New-TimeSpan
$b $(Get-Date)
(‘{0} {1}Day(s),{2}Hour(s),{3}Min(s),{4}Seconds’
-f $s,$LastBoot.Days,$lastboot.Hours,$LastBoot.Minutes,
$LastBoot.Seconds) | out-file
C:\temp\UptimeReport.txt -append -Encoding ascii
}
Catch
{
(‘{0} Server is notreachable’ -f
$s)| Out-File C:\temp\offline.txt -Append -Encoding ascii
}
}
Comments
Post a Comment