Check and restart a Windows service
Deploy via your RMM as a scheduled health-check script or on-demand remediation task. Set the ServiceName variable to match the service you want to monitor — for example 'Spooler' for the print spooler or 'WinDefend' for Windows Defender. The script logs the before and after state so you can confirm remediation in your RMM console.
Code
param(
[string]$ServiceName = "Spooler"
)
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($null -eq $svc) {
Write-Error "Service '$ServiceName' not found on $env:COMPUTERNAME"
exit 1
}
$before = $svc.Status
Write-Output "[$env:COMPUTERNAME] $ServiceName status before: $before"
if ($svc.Status -ne "Running") {
try {
Start-Service -Name $ServiceName -ErrorAction Stop
$svc.Refresh()
Write-Output "[$env:COMPUTERNAME] $ServiceName restarted — status now: $($svc.Status)"
exit 0
} catch {
Write-Error "Failed to start '$ServiceName': $($_.Exception.Message)"
exit 2
}
} else {
Write-Output "[$env:COMPUTERNAME] $ServiceName is already running. No action taken."
exit 0
}How to use this script
Deploy via your RMM as a scheduled health-check script or on-demand remediation task. Set the ServiceName variable to match the service you want to monitor — for example 'Spooler' for the print spooler or 'WinDefend' for Windows Defender. The script logs the before and after state so you can confirm remediation in your RMM console.
Review the script and test in a non-production environment before running at scale.
Related Endpoints scripts
Find endpoints with low disk space
Queries all drives on the local machine and flags any volume with less than 10% free space.
PowerShell · EndpointsClear Windows Update cache
Stops Windows Update services, clears the SoftwareDistribution download cache, then restarts the services.