MSP·OUTPOST
Menu
PowerShell · Endpoints

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.

Script

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
}
Usage

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.

Tags
endpointsservicesremediationrmm