← script library
Check and Restart a Windows Service with PowerShell
Checks & DiagnosticsAugust 17, 2026
Looks up one service by name, starts it when it is stopped, and restarts it when it is already running so a wedged process gets a clean slate. Every state change is written back through the ServerEngine log marker, so the run history shows what the service was doing before the fix, not only that something was restarted.
powershell
# Restart Service
# Author: SENTRI AI Engine | Date: 2026.08.14
#-----------------------------------------------------------------
$Service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($null -eq $Service)
{
Write-Host "<WRITE-LOG = ""*Service: $ServiceName not found.*"">"
continue
}
if ($Service.Status -ne 'Running')
{
Write-Host "<WRITE-LOG = ""*Service: $ServiceName is down! Starting...*"">"
$Service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
Start-Service -Name $ServiceName
Start-Sleep 2
$Service.Refresh()
if ($Service.Status -eq 'Running') {
Write-Host "<WRITE-LOG = ""*Service: $ServiceName started successfully.*"">"
} else {
Write-Host "<WRITE-LOG = ""*Service: $ServiceName failed to start.*"">"
}
}
else {
$Service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
Restart-Service -Name $ServiceName -Force
Start-Sleep 2
$Service.Refresh()
if ($Service.Status -eq 'Running') {
Write-Host "<WRITE-LOG = ""*Service: $ServiceName restarted successfully.*"">"
} else {
Write-Host "<WRITE-LOG = ""*Service: $ServiceName failed to start.*"">"
}
}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.
More in Checks & Diagnostics
Ready when you are.
Try ServerEngine free for 7 days.