Uptime (Windows) powershell
Posts uptime in days. Useful for "find machines that have not rebooted in N days" alerts.
Placeholders only. Before running, replace
YOUR_URL with your capture endpoint's POST URL
.
(Open this page from your capture object to have these auto-filled.)
# uptime.ps1 — days since last boot.
$Url = "YOUR_URL/uptime"
$BootTime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
$UptimeS = [int]((Get-Date) - $BootTime).TotalSeconds
$Body = (@{
hostname = $env:COMPUTERNAME
uptime_seconds = $UptimeS
uptime_days = [math]::Round($UptimeS / 86400, 2)
last_boot = $BootTime.ToString("o")
}) | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $Url -Method Post -Body $Body `
-ContentType "application/json" -TimeoutSec 15 | Out-Null
Recommended pairing
Add a capture.value check to this capture object.
json_path = uptime_days, op = >, threshold = 30 (nag for reboots).
What is the filename?
uptime.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com