How to Use Get-Service in Powershell

How to Use Get-Service in Powershell

The Get-Service PowerShell cmdlet lets you list and inspect services on a local or remote Windows machine. It's one of the most useful tools for checking service status, troubleshooting issues, or filtering based on properties like name, status, or service start type.

What Does the Get-Service Cmdlet Do?

The Get-Service cmdlet retrieves information about the services installed on a system. Each returned item is a service object representing a Windows service. This includes both device driver services and standard network-related services.

By default, the Get-Service command lists services with the following columns:

  • Status – Indicates whether the service is Running, Stopped, or Paused.
  • Name – The service name used internally by Windows.
  • DisplayName – The human-readable name shown in tools like the Services MMC snap-in.

This cmdlet is commonly used to:

  • Check whether a service like the WinRM service is running
  • Display services by their DisplayName
  • List services with specific patterns in their names
  • View dependent services or examine service dependency relationships

Because it outputs .NET ServiceController objects, you can also access any property of service objects, such as StartType, CanPauseAndContinue, and more.

Here's the basic syntax of the Get-Service cmdlet:

Get-Service


You can also provide additional parameters to filter or expand the results:

Get-Service [-Name] <String[]> [-ComputerName <String[]>]

Get-Service [-DisplayName] <String[]>

Get-Service [-InputObject] <ServiceController[]>



For quick usage, PowerShell also supports the alias gsv for Get-Service.

The command supports wildcards for matching service names and display names, making it easy to list services that match certain criteria. For example:

Get-Service -Name "wmi*"

Get-Service -DisplayName "*network*"



Key Parameters of the Get-Service Cmdlet

The Get-Service cmdlet comes with several parameters that allow you to filter, manage, and retrieve specific services from your system. Below are the key parameters:

  • -Name: Filters services by their internal name. This can be a specific name or a wildcard to match multiple services. This is one of the most commonly used options when querying service status or checking on device service availability.
  • -DisplayName: Filters services by their user-friendly display name. This is especially useful when you're unsure of the exact service name and just know the service's public label.
  • -DependentServices: Retrieves a list of services that depend on the specified service. This is helpful when you're managing dependencies or checking service relationships. Helps avoid accidentally disrupting other network-related services or device driver services.
  • -RequiredServices: Shows the services that the specified service relies on in order to function correctly, exposing the service's dependency chain.
  • -Include: Allows you to include services that match specific patterns from the results.
  • -Exclude: Excludes services from the results based on matching patterns.
  • -InputObject: Accepts ServiceController objects from other cmdlets, allowing you to chain commands together in more advanced workflows.

What can You Use Get-Service for?

  1. List all services on the local system
    Retrieve a complete list of services, including their current status (Running, Stopped) and display names, to get an overview of what's active on the machine.
  2. Filter services by name or display name
    Search for specific services by using either the -Name or -DisplayName parameter. Useful for troubleshooting or verifying the state of a particular service.
  3. View services with dependencies
    Use the -DependentServices or -RequiredServices flags to understand service relationships, which is critical when diagnosing service startup issues or configuration dependencies.
  4. List services by status
    Combine Get-Service with Where-Object to filter services based on their current status (e.g., only running or stopped services), helping admins focus on what’s relevant.
  5. Pipe service objects into other cmdlets
    The Get-Service cmdlet is commonly used in scripts where service objects are passed to other commands like Start-Service, Stop-Service, or Restart-Service.

Prerequisites

Before using the Get-Service cmdlet, ensure you have the following:

  • PowerShell: You should have PowerShell 7.5 or later installed. This cmdlet is available in both Windows PowerShell and PowerShell Core.
  • Permissions: Depending on the service you are querying, you may need administrative privileges to retrieve information about certain services or modify their state.
  • Target System: If querying services on a remote system, ensure that the necessary remoting setup (like WinRM) is configured and you have appropriate access.

How to Use Get-Service: Example Commands with Output

Here are a few practical examples of how you can use the Get-Service cmdlet in various scenarios:

1. List All Services

To list all the services running on your machine, simply use:

Get-Service


This command will display a list of services, showing their status, name, and display name.

2. Check if a Specific Service is Running

If you want to check whether a specific service (e.g., WinRM) is running, use the -Name parameter:

Get-Service -Name "WinRM"


This will return the status of the WinRM service (Running, Stopped, etc.).

3. List Services with Specific Patterns in Their Names

You can use wildcards to list services that match a pattern in their name. For example:

Get-Service -Name "wmi*"



This will list all services whose names start with wmi.

4. Display Services with a Specific Display Name

If you're not sure about the internal name but know the display name of a service, you can use the -DisplayNameparameter:

Get-Service -DisplayName "Windows Remote Management (WS-Management)"



This command will show the service with the specified display name.

5. View Services Dependent on Another Service

To see which services depend on the WinRM service, use the -DependentServices flag:

Get-Service -Name "WinRM" -DependentServices



This will list all services that depend on WinRM.

6. View Services Required by Another Service

To see which services are required by WinRM, use the -RequiredServices flag:

Get-Service -Name "WinRM" -RequiredServices



This will show the services listed under the ServicesDependedOn property, which are critical for WinRM to function.

7. Filter Services by Status (Running/Stopped)

You can filter the list of services based on their status. For example, to list only the running services, use:

Get-Service | Where-Object { $_.Status -eq 'Running' }



This filters the output to only show services that are currently running.

8. Use Piping to Chain Commands

Get-Service can be used in combination with other cmdlets. For example, to stop a specific service after retrieving it, you can pipe the result:

Get-Service -Name "WinRM" | Stop-Service


This command retrieves the WinRM service and immediately stops it.

Final Note

The Get-Service cmdlet is a powerful tool for managing and troubleshooting services on Windows machines. By understanding how to leverage its various parameters, you can easily filter and control services, ensuring your system runs smoothly and efficiently.