PowerShell: Listing Windows Services


Most people know you can see all the running services in a Windows operating system by employing services.msc through the Search box or Run command. From there, you can filter by Name or Startup Type to view what services are started, which are stopped, and which should have been started and perhaps failed.

You can also retrieve this information through PowerShell. The benefit of using PowerShell is that you can filter by Startup Type (startmode in PowerShell) or Status (state). For example, by using a PowerShell command you can find all services that have a Startup Type of Automatic and a Status of Stopped. This information is filtered and presented quickly to you. This saves you time from sorting and scrolling through the list of services.

Methodology

To find the services we are looking for, we will use the Get-WmiObject cmdlet within PowerShell. It is used to carry out system administration tasks and can even be run against remote computers. This cmdlet gets an instance of Windows Management Instrumentation (WMI) and any of its available sub-classes. We could also use its alias gwmi to shorten the cmdlet call.

Script To Find All Services

If we want to run a PowerShell command to find all services on our operating system, we can use a script similar to the one shown in the image below. It retrieves the Name, DisplayName, State and StartMode of the services and then sorts them by State and Name. Setting the script up this way lets us see all of the Running and Stopped services grouped together. This provides a quick glimpse into services we suspect is causing a problem, especially if one is supposed to be Running and it is set to Stopped.

Script To Filter Services

If we need to be more precise in our searching, we can apply filters to our Get-WmiObject calls so that they return only the information we need. Using our example from above, to find all services that have a Startup Type of Automatic and a Status of Stopped we can apply a filter to return only services that meet these criteria.

Conclusion

In this article, we reviewed how we can use the PowerShell Get-WmiObject cmdlet to find all the running services on an OS. We also saw how we can filter the data returned so it only shows the information we need to troubleshoot a problem. Using this filtering capability, we can see how much easier it is to quickly find services that meet our troubleshooting criteria.

See Also

Download a copy of each PowerShell script from the TechNet Gallery:

References