@echo off setlocal set "SERVICE_NAME=%~1" if "%SERVICE_NAME%"=="" set "SERVICE_NAME=Spooler" powershell -NoProfile -ExecutionPolicy Bypass -Command "$s = Get-Service -Name $env:SERVICE_NAME -ErrorAction SilentlyContinue; if ($null -eq $s) { Write-Host ('Service not found: ' + $env:SERVICE_NAME); exit 2 }; Write-Host ('Service: {0} Status: {1}' -f $s.Name, $s.Status); if ($s.Status -eq 'Running') { exit 0 } else { exit 1 }" set "RC=%ERRORLEVEL%" if not "%RC%"=="0" echo Service check failed with code %RC% exit /b %RC%