- Reference
- Module:
- Microsoft.PowerShell.Management
Gets the services on the computer.
Syntax
Get-Service [[-Name] <String[]>] [-DependentServices] [-RequiredServices] [-Include <String[]>] [-Exclude <String[]>] [<CommonParameters>]
Get-Service [-DependentServices] [-RequiredServices] -DisplayName <String[]> [-Include <String[]>] [-Exclude <String[]>] [<CommonParameters>]
Get-Service [-DependentServices] [-RequiredServices] [-Include <String[]>] [-Exclude <String[]>] [-InputObject <ServiceController[]>] [<CommonParameters>]
Description
This cmdlet is only available on the Windows platform.
The Get-Service
cmdlet gets objects that represent the services on a computer, including runningand stopped services. By default, when Get-Service
is run without parameters, all the localcomputer's services are returned.
You can direct this cmdlet to get only particular services by specifying the service name or thedisplay name of the services, or you can pipe service objects to this cmdlet.
Examples
Example 1: Get all services on the computer
This example gets all of the services on the computer. It behaves as though you typedGet-Service *
. The default display shows the status, service name, and display name of eachservice.
Get-Service
Example 2: Get services that begin with a search string
This example retrieves services with service names that begin with WMI
(Windows ManagementInstrumentation).
Get-Service "wmi*"
Example 3: Display services that include a search string
This example displays services with a display name that includes the word network
. Searching thedisplay name finds network-related services even when the service name doesn't include Net
, such asxmlprov, the Network Provisioning Service.
Get-Service -Displayname "*network*"
Example 4: Get services that begin with a search string and an exclusion
This example only gets the services with service names that begin with win
, except for the WinRMservice.
Get-Service -Name "win*" -Exclude "WinRM"
Example 5: Display services that are currently active
This example displays only the services with a status of Running
.
Get-Service | Where-Object {$_.Status -eq "Running"}
Get-Service
gets all the services on the computer and sends the objects down the pipeline. TheWhere-Object
cmdlet, selects only the services with a Status property that equals Running
.
Status is only one property of service objects. To see all of the properties, typeGet-Service | Get-Member
.
Example 6: List the services on the computer that have dependent services
This example gets services that have dependent services.
Get-Service | Where-Object {$_.DependentServices} | Format-List -Property Name, DependentServices, @{ Label="NoOfDependentServices"; Expression={$_.dependentservices.count} }Name : AudioEndpointBuilderDependentServices : {AudioSrv}NoOfDependentServices : 1Name : DhcpDependentServices : {WinHttpAutoProxySvc}NoOfDependentServices : 1...
The Get-Service
cmdlet gets all the services on the computer and sends the objects down thepipeline. The Where-Object
cmdlet selects the services whose DependentServices property isn'tnull.
The results are sent down the pipeline to the Format-List
cmdlet. The Property parameterdisplays the name of the service, the name of the dependent services, and a calculated property thatdisplays the number of dependent services for each service.
Example 7: Sort services by property value
This example shows that when you sort services in ascending order by the value of their Statusproperty, stopped services appear before running services. This happens because the value ofStatus is an enumeration, in which Stopped
has a value of 1
, and Running
has a value of4
. For more information, seeServiceControllerStatus.
To list running services first, use the Descending parameter of the Sort-Object
cmdlet.
Get-Service "s*" | Sort-Object statusStatus Name DisplayName------ ---- -----------Stopped stisvc Windows Image Acquisition (WIA)Stopped SwPrv MS Software Shadow Copy ProviderStopped SysmonLog Performance Logs and AlertsRunning Spooler Print SpoolerRunning srservice System Restore ServiceRunning SSDPSRV SSDP Discovery ServiceRunning ShellHWDetection Shell Hardware DetectionRunning Schedule Task SchedulerRunning SCardSvr Smart CardRunning SamSs Security Accounts ManagerRunning SharedAccess Windows Firewall/Internet Connectio...Running SENS System Event NotificationRunning seclogon Secondary Logon
Example 8: Get the dependent services of a service
This example gets the services that the WinRM service requires. The value of the service'sServicesDependedOn property is returned.
Get-Service "WinRM" -RequiredServices
Example 9: Get a service through the pipeline operator
This example gets the WinRM service on the local computer. The service name string, enclosed inquotation marks, is sent down the pipeline to Get-Service
.
"WinRM" | Get-Service
Parameters
-DependentServices
Indicates that this cmdlet gets only the services that depend upon the specified service.
Type: | SwitchParameter |
Aliases: | DS |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DisplayName
Specifies, as a string array, the display names of services to be retrieved. Wildcards arepermitted.
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-Exclude
Specifies, as a string array, a service or services that this cmdlet excludes from the operation.The value of this parameter qualifies the Name parameter. Enter a name element or pattern, suchas s*
. Wildcards are permitted.
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-Include
Specifies, as a string array, a service or services that this cmdlet includes in the operation. Thevalue of this parameter qualifies the Name parameter. Enter a name element or pattern, such ass*
. Wildcards are permitted.
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
-InputObject
Specifies ServiceController objects representing the services to be retrieved. Enter a variablethat contains the objects, or type a command or expression that gets the objects. You can pipe aservice object to this cmdlet.
Type: | ServiceController[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
Specifies the service names of services to be retrieved. Wildcards are permitted.
Type: | String[] |
Aliases: | ServiceName |
Position: | 0 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-RequiredServices
Indicates that this cmdlet gets only the services that this service requires. This parameter getsthe value of the ServicesDependedOn property of the service.
Type: | SwitchParameter |
Aliases: | SDO, ServicesDependedOn |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | True |
Inputs
ServiceController
You can pipe a service object to this cmdlet.
String
You can pipe a service name to this cmdlet.
Outputs
ServiceController
This cmdlet returns objects that represent the services on the computer.
Notes
PowerShell includes the following aliases for Get-Service
:
- Windows:
gsv
This cmdlet is only available on Windows platforms.
Beginning in PowerShell 6.0, the following properties are added to the ServiceControllerobjects: UserName, Description, DelayedAutoStart, BinaryPathName, andStartupType .
This cmdlet can display services only when the current user has permission to see them. If thiscmdlet does not display services, you might not have permission to see them.
To find the service name and display name of each service on your system, type Get-Service
. Theservice names appear in the Name column, and the display names appear in the DisplayNamecolumn.
Note
Typically, Get-Service
returns information about services and not driver. However, if youspecify the name of a driver, Get-Service
returns information about the driver.
- Enumeration doesn't include device driver services
- When a wildcard is specified, the cmdlet only returns Windows services
- If you specify the Name or DisplayName that is an exact match to a device service name,then the device instance is returned
When you sort in ascending order by status value, Stopped
services appear before Running
services. The Status property of a service is an enumerated value in which the names of thestatuses represent integer values. The sort is based on the integer value, not the name. Running
appears before Stopped
because Stopped
has a value of 1
, and Running
has a value of 4
. Formore information, seeServiceControllerStatus.
- New-Service
- Restart-Service
- Resume-Service
- Set-Service
- Start-Service
- Stop-Service
- Suspend-Service
- Remove-Service