Skip to main content

Posts

Showing posts from March, 2023

PowerShell check device uptime since last reboot

Checking how long the machine or server is running since last reboot or maintenance is sometimes necessary. To measure the device performance or stability of the server or computer. In Windows, PowerShell is quite handy to to check the uptime of the server. Here's a simple code snippet to do check how long the server has been running since its last reboot. $Last_reboot_time = Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} $Today = Get-Date $uptime = NEW-TIMESPAN –Start $Last_reboot_time.LastBootUpTime –End $Today $xdays=$uptime.Days $xhours=$uptime.TotalHours $xhours=[math]::Round($xhours,2) write-output ("Computer is up since last reboot for: $xdays day/s and  $xhours  hours") Sample output of the code below: Computer is up since last reboot for: 1 day/s and  45.98  hours Cheers! Take care. Till next Time. Stay safe! and Keep things up!  Do ASAP,  A lways  S ay  A   P rayer ... P