Getting System Uptime

by Sep 3, 2009

If you'd like to determine a system's uptime, you should use WMI and convert the WMI date into a more readable format:

function Get-SystemUptime
{
$os = Get-WmiObject Win32_OperatingSystem
[Management.ManagementDateTimeConverter]::ToDateTime($os.LastBootUpTime)
}

You can even query remote systems by adding the -computerName parameter to Get-WmiObject. Use the shortcut ETS has created if you don't want to remember the .NET class:

function Get-SystemUptime
{
$os = Get-WmiObject Win32_OperatingSystem
$os.ConvertToDateTime($os.LastBootupTime)
}

Twitter This Tip! ReTweet this Tip!