PowerShell Snippet: Getting a Remote Computers Uptime

The below bit of PowrShell will return the uptime and last boot time stamp of a remote Windows computer.

Change the $server variable as needed.

#
# Get Uptime
#
$server = "MyServer01"

$os = gwmi Win32_OperatingSystem -computerName $server
$boottime = $OS.converttodatetime($OS.LastBootUpTime)
$uptime = New-TimeSpan (get-date $boottime)
 
$uptime_days = [int]$uptime.days
 
write-host "LAST BOOT TIME =  " $boottime 
write-host "UPTIME (DAYS) =  " $uptime_days
PowerShell uptime snippet

1 thought on “PowerShell Snippet: Getting a Remote Computers Uptime”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.