Windows service status powershell
Reports running/stopped status for a list of Windows services. Alert if any service that should be running isn't.
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.)
# service-status.ps1 — status of named services.
$Url = "YOUR_URL/services"
$Watch = @("W3SVC", "MSSQLSERVER", "BITS") # services that should be running
$Statuses = @{}
$AnyStopped = $false
foreach ($name in $Watch) {
$svc = Get-Service -Name $name -ErrorAction SilentlyContinue
if ($svc) {
$running = $svc.Status -eq 'Running'
$Statuses[$name] = @{ found = $true; status = "$($svc.Status)"; running = $running }
if (-not $running) { $AnyStopped = $true }
} else {
$Statuses[$name] = @{ found = $false; status = "missing"; running = $false }
$AnyStopped = $true
}
}
$Body = (@{
hostname = $env:COMPUTERNAME
services = $Statuses
any_stopped = $AnyStopped
}) | ConvertTo-Json -Compress -Depth 4
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 = any_stopped, op = ==, threshold = true. Or one check per service: json_path = services.W3SVC.running, op = ==, threshold = false.
What is the filename?
service-status.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com