PowerShell Get-Service Tutorial

Operating systems heavily use services to provide different native and 3rd party services without any interruption. Windows PowerShell provides the Get-Service command in order to list Windows services. The Get-Service can be used to list, filter, or iterate over Windows services in an easy way.

List All Services

The Get-Service command can be used to list all services. The listed services can be indifferent states like running, stopped, etc. The listing shows information like Status, Name, and DisplayName. The Status is about the current status of the service like Stopped, Running, etc. The Name is about the canonical name used by the Windows operating system. The DisplayName is used to name service in a more human-friendly way.

PS> Get-Service
List All Services

Display Services By Name

We can display specific services by filtering them according to their names. In the following example, we only display services whose names contain the term “win”. We use the “*win*” search term.

PS> Get-Service "*win*"
Display Services By Name

Display Services Those Starts with Specified String

We can display services those starts with the specified string. In the following example, we only display those service names starting with “win”.

PS> Get-Service "win*"

Exclude Services From Search

While searching services according to their names we can exclude some of them by using the -Exclude attribute. In the following example, we search services with the name “win” but exclude those containing “Winmgmt”.

PS> Get-Service "*win*" -Exclude "Winmgmt"

Display Active Services

Windows service can be in different states like Running or Stopped. We can display only Running services by querying their status using the Where-Object .

PS> Get-Service | Where-Object {$_.Status -eq "Running"}

List Service with Dependent Services

Services may require other services to work properly. We can list a service dependent services using the -RequiredServices attribute.

PS> Get-Service -RequiredServices "WinRM" 
List Service with Dependent Services

Sort Services By Name

Different services are named differently. The services are listed randomly. We can sort services by their names with the help of the Sort-Object command.

PS> Get-Service | Sort-Object Name

Sort Services By Status

We can also sort services according to their status. Like the previous example, we use the Sort-Object command to sort services according to their status.

PS> Get-Service | Sort-Object Status
See also  What Is NetBIOS?

Leave a Comment