System Up Time
The PowerShell team have just posted about obtaining system up time using a .NET class to convert the WMI date format to something thats readable
http://blogs.msdn.com/powershell/archive/2009/08/12/get-systemuptime-and-working-with-the-wmi-date-format.aspx
There is a WMI only way of doing this
$os = Get-WmiObject -Class Win32_OperatingSystem
$os.ConvertToDateTime($os.LastBootUpTime)
But this gives the date and time the system was last booted. If you want the actual up time then use
(get-date) - $os.ConvertToDateTime($os.LastBootUpTime)
which generates a timespan object
Days : 0
Hours : 1
Minutes : 53
Seconds : 8
Milliseconds : 461
Ticks : 67884618000
TotalDays : 0.0785701597222222
TotalHours : 1.88568383333333
TotalMinutes : 113.14103
TotalSeconds : 6788.4618
TotalMilliseconds : 6788461.8
which gives the actual up time. The .NET method can be substituted for the WMI method if required
Technorati Tags:
PowerShell,
WMI,
UpTime