PowerShell script to find status of service on a remote computer

Here’s a quick one-liner to retrieve the status of a Windows service on a remote computer using Powershell. You don’t need PowerShell remoting for this to work because it uses WMI.

This example uses the SNMP Trap service, so just replace that text with the particular service you’re looking for. Also replace remotecomputer with the name of the computer you are querying. If you remove -computername remotecomputer you will query your local computer.

Get-WmiObject -Class win32_service -ComputerName remotecomputer 
| ? { $_.name -like "snmptrap" } 
| % { "$($_.name) is $($_.state)" }

output:

SNMPTRAP is Stopped

Isn’t PowerShell great?!