← script library

Check Server Uptime with PowerShell

Checks & DiagnosticsAugust 17, 2026

Reports the last boot time and how long the server has been up, and warns once uptime passes the configured number of days. Long uptime is rarely a problem in itself, but it is an excellent proxy for updates that were installed and never activated by a restart.

powershell
# Check System Uptime
# Single use case: report time since last boot, warn above threshold
#-----------------------------------------------------------------

function Write-Log {
    param($Message)
    Write-Host "<WRITE-LOG = `"*$Message*`">"
}

# --- Parameters (replace via ServerEngine API parameters if needed) ---
$WarnUptimeDays = 45

$os = Get-CimInstance -ClassName Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
$days = [math]::Round($uptime.TotalDays, 1)

Write-Log "Last boot: $($os.LastBootUpTime.ToString('yyyy-MM-dd HH:mm'))"
Write-Log "Uptime: $days days ($($uptime.Days)d $($uptime.Hours)h $($uptime.Minutes)m)"

if ($days -gt [double]$WarnUptimeDays) {
    Write-Log "WARNING: uptime exceeds $WarnUptimeDays days - consider a maintenance reboot (pending updates may be waiting)."
} else {
    Write-Log "Uptime is within the $WarnUptimeDays day threshold."
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.