Introduction to PowerShell Get-Service
Get-Service cmdlet in PowerShell is used for retrieving the services (Operating systems and applications) installed on the local computer and the remote computers as well along with their Start type, status, name and display name of the services. PowerShell console will display all the services which are present in the Services.msc MMC. By default Get-Service cmdlet provides the information about local computer services until the –ComputerName parameter specified for the remote computers. We can also retrieve the dependent services with this cmdlet. This cmdlet is part of the Microsoft.PowerShell.Management module.
[[-Name] <String>] [[-DisplayName] <String>
[-DependentServices] [-RequiredServices] [-Include <String>] [-Exclude <String>] [-InputObject <ServiceController>] [<CommonParameters>]
Below are the parameters:
- Name: This parameter is for the name or alias name of the service. It is a string object. You can provide multiple services names (aliases) separated by comma (,). Wildcard character (*) is permitted. For example, the spooler is the alias name of the “Print Spooler” service.
- DisplayName: This parameter is for the display name of the service. It is a string datatype. You can provide multiple display names separated by comma (,). Wildcard character (*) is permitted. For example, “Windows Management Instrument” is the display name of the winmgmt service alias.
- DependentServices: When this parameter is specified, it retrieves the dependent services of the provided service name. This parameter must be used with the –Name or the –DisplayName parameter, otherwise, PowerShell will retrieve all the dependent services.
- RequiredServices: This parameter specifies the services which are required to start the given service(s). You must specify the –Name or –DisplayName parameter, otherwise, PowerShell will retrieve all the required services.
- Include: This parameter specifies the service name to include while retrieving the Service information. The value of this parameter qualifies the Name You can use the wildcard character (*). For example, When you specify S*, it will retrieve all the services that start with the S.
- Exclude: This parameter specifies the service name to exclude while retrieving the set of services information. The value of this parameter qualifies the Name You can use the wildcard character (*). For example, when you specify S*, it will retrieve all the services excluding services starting with S*.
- InputObject: You can provide multiple services as a variable to the input object parameter to retrieve the services from Get-Service cmdlet.
- CommonParameters: These parameters are for the error and warning handling, debug, verbose, etc.. parameters. For example, -ErrorAction, -ErrorVariable, -WarningVariable, -WarningAction, -Verbose, -Debug, -OutBuffer, -OutVariable.
Examples to Implement PowerShell Get-Service
Below are examples to implement:
1. Get-Service with the – Name Parameter
When you don’t specify any parameter with Get-Service cmdlet, it default takes the –Name parameter. To retrieve the service information with the –Name parameter, we need to provide the valid service name. The default output will be Status, Name and DisplayName format.
Get-Service -Name Winmgmt
Explanation: You can also use the wildcard to retrieve the information.
Get-Service -Name Win*
Here, Get-Service will retrieve all the services starting with the “Win”.
Explanation: You can get the multiple services information with the –Name parameter by separating them with a comma (,).
Get-Service -Name Winmgmt, WinRM, Spooler
2. Get-Service with the – DisplayName parameter
You can provide the displayname parameter to the Get-Service cmdlet to retrieve services information.
Get-Service -DisplayName "Print Spooler"
To use the wildcard character (*),
Get-Service -DisplayName "*Spooler*"
3. Get-Service with the – DependedService
To get the depended services information of the particular service, use the below command.
Get-Service Winmgmt -DependentServices
Explanation: In the above output, the Windows management instrument service is dependent on the given services in the output.
This parameter also works with the Display name and the Wildcard character and even for the multiple services.
Get-Service -DisplayName "Windows Management Instrumentation" -DependentServices
Explanation: You can check the same in the Services property in the “depends on” the section from the Services.msc console.
4. Get-Service with the – RequiredService
With this parameter, you will get the required services information (particular service which depends on the other services).
Get-Service Winmgmt -RequiredServices
Explanation: The above output mentions that the RPCSS service is required for Winmgmt service. Meaning that Winmgmt service is in the dependent list of the RPCSS service. You can check the same in the service property.
5. Get-Service with the – Include Parameter
When you use the include parameter, it searches for the content mentioned after include parameter. Wildcard character (*) is accepted. For example,
Get-Service -Include S*, *print*
Explanation: The above command will include all the services that start with S and contain Print in the service name. you can retrieve the same output with the Name parameter as well.
6. Get-Service with the – Exclude parameter
With the exclude parameter, service names are excluded and the rest of the services will be displayed.
Get-Service -Exclude S*, A*, *Windows*
Explanation: The above command excludes services starting with S, A and which contain Windows in the output command.
Explanation: You can only qualify search for the Name parameter but not for the others like DisplayName, Start type, etc.
7. Get-Service with the Format-List
Get-Service cmdlet provides the default output, which contains only a few table items like Display Name, Name, and status but if you want to display all the properties then pipeline the Format-List * (fl *) alias.
Get-Service Spooler | Format-List *
8. Get-Service with the Select-Object Pipeline
You can retrieve the selected properties with the Select-Object (alias: Select) parameter.
Get-Service winmgmt, winrm | Select Name, DisplayName, Starttype, Status
With the Get-Service you can retrieve the service information on the local computer and the remote computers, but you can also pipeline Start-Service and Stop-Service to Start or stop the services on local and remote computers.
This is a guide to PowerShell Get-Service. Here we discuss Syntax, parameters and top 8 examples to implement with proper codes and outputs. You can also go through our other related articles to learn more –