PowerShell: How to Use Get-Service and Filter Results


You can use the Get-Service cmdlet in PowerShell to get all services on a computer, including running and stopped services.

Often you may want to filter the results of the Get-Service cmdlet to only show the services that contain a particular string.

You can use the following methods to do so:

Method 1: Get-Service and Filter for Exact Name

Get-Service -Name Audiosrv

This particular example will only display the results for the service named Audiosrv.

Method 2: Get-Service and Filter for Services that Contain String

Get-Service -Name *Audio*

This particular example will display the results for all services that contain Audio in the name of the service.

Method 3: Get-Service and Filter for Services that Contain One of Several Strings

Get-Service | Where-Object {$_.name -like '*Audio*' -or $_.name -like '*Enum*'}

This particular example will display the results for all services that contain either Audio or Enum in the name of the service.

The following examples show how to use this syntax in practice.

Example 1: Use Get-Service and Filter for Exact Name

We can use the following syntax with the Get-Service cmdlet in PowerShell to only display the services with the exact name of Audiosrv:

Get-Service -Name Audiosrv

The following screenshot shows how to use this syntax in practice:

PowerShell Get-Service filter for exact name

This only returns results for the service with the exact name of Audiosrv.

Example 2: Use Get-Service and Filter for Services that Contain String

We can use the following syntax with the Get-Service cmdlet in PowerShell to only display the services that contain Audio somewhere in the service name:

Get-Service -Name *Audio*

The following screenshot shows how to use this syntax in practice:

PowerShell Get-Service filter for services that contain string

This returns results for all services that contain Audio somewhere in the service name.

Example 3: Use Get-Service and Filter for Services that Contain One of Several Strings

We can use the following syntax with the Get-Service cmdlet in PowerShell to only display the services that contain either Audio or Enum somewhere in the service name:

Get-Service | Where-Object {$_.name -like '*Audio*' -or $_.name -like '*Enum*'} 

The following screenshot shows how to use this syntax in practice:

PowerShell Get-Service filter for multiple services

This returns results for all services that contain either Audio or Enum somewhere in the service name.

Note: You can find the complete documentation for the Get-Service cmdlet in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Filter for Unique Objects
PowerShell: How to Use Get-ChildItem with Filter
PowerShell: How to Use Get-ChildItem with Multiple Filters

Leave a Reply