List Windows Services using PowerShell

Windows services are Windows executables that run in the background to support the working of some Windows processes. These services can be started, stopped, restarted, suspended, resumed, or even removed.

Note: Some services are vital to the workings of the OS system, and removing or stopping them may cause the OS to restart or even crash.

The list of all Windows services can be fetched in the Windows PowerShell using the Get-Service cmdlet. The problem with the command is that it may generate a long list, so what you are looking for might be hard to find.

This article will discuss some examples of working with Get-Service efficiently.

Example 1: Listing all Windows Services

You can get the list of all Windows services by running the command.

The command outputs Windows services with three properties:

  • Status – shows the status of the service – running or stopped,
  • Name – the name of the service,
  • DisplayName – a more human-readable description of what the service is all about.

Example 2: Sort the Get-Service Output by a Given Field

Note that the Get-Service output is, by default, sorted by Name (see Example 1). You can sort the output with any of the other fields. For example,

Example 3: Get Services with Specific Names

To get the specific services, provide the names of the services you want to fetch, separated by a comma. Note that this only works with Name and DisplayName properties.

Example 4: Filtering the Get-Service List Using Wildcards

You can also use wildcards to filter the outputs based on Name or DisplayName. For example,

* wildcard character matches zero or more characters. That means WLAN* matches services starting with the string “WLAN”, “*Remote Desktop*” matches services with the substring “Remote Desktop” in their DisplayName, and P*s matches services that start with P and ends with s in their DisplayName.

You can read more about PowerShell wildcards here.

Example 5: Filter Services Based on their Status

We cannot filter the services directly based on Status as we did in Examples 3 and 4. But we can still filter by piping output into the Where-Object cmdlet and issuing the condition, as shown below.

The command above will fetch all services whose Status is equal (-eq) to “Stopped”.

Example 6: Selecting other Properties in Get-Service

Get-Command does not come with only the three properties we have discussed. There is More. You can see all methods and objects of Get-Service by running the command

Apart from Name, DisplayName, and Status, the other objects include Description, StartupType, etc.

You can then pick the properties you need from the available ones using the Select-Object cmdlet. For example, the following command shows the Name, Description of the service, and properties starting with “Start”.

Example 7: Getting all Services that can be Paused Without OS Restarting

As said earlier, some services are critical to the functionality of the OS. Any attempt to pause such services may cause the OS to restart. You can check for those vital services using the command:

If you want to see the services that can be suspended and resumed without a problem, you can set the CanPauseAndContinue to “true”.

Example 8: Excluding/Including Some Services from/to the List

The Get-Service commands have the -Include and -Exclude options that allow us to filter our outputs even more.

These two options work for the Name parameter only and accept wildcards. Here is an example.

The command above gets all services whose Name starts with “vmi” but excludes vmicshutdown and vmicrdv services. The -Include option works similarly but does the opposite.

After going through Examples 1 through 8, you should be able to get the Get-Service list containing the services you need. The next is to take care of the output.

Example 9: Output to a Grid View

The default behavior is that you will see the output of Get-Service on the PowerShell console. We can send the output into grid view instead of using the Out-GridView cmdlet, as shown below.

After running the command above, a new grid-like window will appear and show the result of the Get-Service command.

Example 10: Write the Output to a File

Alternatively, you can send the results to a file using the Out-File command, as shown below.

The command will send the list of all running services into the running_services.txt.

Conclusion

This guide explains how to use Get-Service to list Windows Services on PowerShell. After going through the 10 examples covered in this article, you should be able to filter your services list and control the output based on your needs.