Command
$OS = Get-CimInstance Win32_OperatingSystem
$Uptime = (Get-Date) - $OS.LastBootUpTime
[PSCustomObject]@{
DernierDemarrage = $OS.LastBootUpTime
Jours = $Uptime.Days
Heures = $Uptime.Hours
Minutes = $Uptime.Minutes
}When to use it
Use this to confirm whether a workstation really restarted after an update or incident.
How it works
- Windows exposes the last boot time through Win32_OperatingSystem.
- The script then calculates the elapsed uptime.
Precautions
- Windows Fast Startup can sometimes make a shutdown and power-on look different from a full restart.
Rollback
No changes are made.