Test Service Responsiveness
All PowerShell Versions
To test whether a particular service is still responding, use a clever trick. First, ask WMI for the service you want to check. WMI will happily return the process ID of the underlying process.
Next, look up this process, and the process object will tell you whether the process is frozen or responding:
$service = Get-WmiObject -Class Win32_Service -Filter "Name='$ServiceName'"
$processID = $service.processID
$process = Get-Process -Id $processID
This example would check whether the Spooler service is still responding:
PS> Test-ServiceResponding -ServiceName Spooler
Note that the example code assumes that the service is running. If you wanted to, you could add a check to exclude non-running services yourself.
ReTweet this Tip!