System Uptime

The ability to obtain the up-time of a system would be beneficial while doing maintenance (software updates in particular).  If an administrator could right click a collection and obtain the system up-time (or last reboot time), it could significantly reduce the guess work as to whether a client restarted after installing an update.   The following PowerShell script returns the system up-time in Days, Hours, and Minutes since last reboot:

$OS = Get-WmiObject Win32_OperatingSystem
$SysUptime = (Get-Date) - $OS.ConvertToDateTime($OS.LastBootUpTime)
$Properties = @{
LastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime)
Uptime = ([String]$SysUptime.Days + " Days " + $SysUptime.Hours + " Hours " + $SysUptime.Minutes + " Minutes")
}
$Obj = New-Object -TypeName PSObject -Property $Properties | select Uptime
Write-Output $Obj.Uptime

 

Running the script will return the following:

0 Days 1 Hours 38 Minutes

 

  • Guest
  • Dec 16 2019
  • Already exists
  • Attach files
  • Chris Muster commented
    17 Aug, 2021 08:33pm

    This exists in the Operating Systems tab of the System Information tool.

  • +2