powershell get last boot time blog

Back in the day, Microsoft had a utility (uptime.exe) which was incredibly useful when managing many servers. It showed how many days the computer had been running since its last boot.  This is particularly useful when troubleshooting issues.

Up until PowerShell 6.0, this was not available natively as a cmdlet. Sure, you could use a WMI cmdlets to get the last boot entry, but you then had to convert it to DateTime object and use math – not ideal when troubleshooting. So, I wrote this script to help get the last boot time on any windows computer that has older versions of PowerShell. One feature this script has over Microsoft’s is that you can specify a remote computer. It uses WMI, so if you allow WinRM, then this should work.

You can either use the script (.ps1) or copy the code as a function into your windows PowerShell profile (see code below). I personally have it in my windows PowerShell profile, that way it loads every time I open a new console.

Script available here: Get-Uptime