Get-Uptime one-liner

To get the uptime locally you can execute on powershell 2.0 and later the following one-liner:

(Date)-([Management.ManagementDateTimeConverter]::ToDateTime((gwmi Win32_OperatingSystem).LastBootUpTime))

If you have remoting enabled on target computers you can also do:

Invoke-Command -ComputerName RemotePC1,RemotePC2 -ScriptBlock {            
    New-TimeSpan -Start (Get-Date) -End (            
        [System.Management.ManagementDateTimeConverter]::ToDateTime(            
            (Get-WmiObject -Class Win32_OperatingSystem).LastBootUpTime            
        )            
    )            
} | Format-Table -AutoSize
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s