Freigeben über


Getting Uptime of Multiple Servers

During a Premier case we needed to get uptime information of several servers in customers environment. To save time we used the function below; function gets server names as arguments and simply converts DMTF datetime format (Date and time representation in WMI) to DateTime, please check reference for more info

You may find the script in action below; and find the attachment in txt format...hope it helps!!

PS C:\Windows\system32> function Get-UpTime
>> {
>> foreach($comp in $args)
>> {
>> $upTime = [Management.ManagementDateTimeConverter]::ToDateTime((gwmi win32_operatingsystem -computer $comp).lastbootuptime)
>> write-host $comp "-> server is up since" $upTime "which means" ([datetime]::now - $upTime).Days "days"
>> }
>> }
>>
PS C:\Windows\system32> Get-UpTime cdvm cdvm2
cdvm -> server is up since 12/23/2009 4:24:34 PM which means 20 days
cdvm2 -> server is up since 12/25/2009 2:42:32 PM which means 18 days
PS C:\Windows\system32>

 

Reference: https://msdn.microsoft.com/en-us/library/system.management.managementdatetimeconverter.todatetime.aspx

Cheers, CanD

Get-UpTime.txt