Jan 232013
 

Checking System Uptime

In a previous tip we explained how you read date and time information from WMI and convert it into a regular date and time information. With this technique, you can then manipulate and calculate with the regular date and time functions. So, this piece of code returns the days a given system is running since the last reboot was done:

$os=Get-WmiObject-ClassWin32_OperatingSystem

$boottime=
[
System.Management.ManagementDateTimeConverter]::
ToDateTime($os.LastBootupTime)

$timedifference=New-TimeSpan-Start$boottime

$days=$timedifference.TotalDays

‘Your system is running for {0:0.0} days.’-f$days

from PowerShell

Leave a Reply