powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Get-Service



NAME
Get-Service

SYNOPSIS
Gets the services on a local or remote computer.

SYNTAX
Get-Service [[-Name] ] [-ComputerName ] [-DependentServices] [-Exclude ] [-Include tring[]>] [-RequiredServices] []

Get-Service -DisplayName [-ComputerName ] [-DependentServices] [-Exclude ] [-Include
] [-RequiredServices] []

Get-Service [-InputObject ] [-ComputerName ] [-DependentServices] [-Exclude ]>] [-Include ] [-RequiredServices] []


DESCRIPTION
The Get-Service cmdlet gets objects that represent the services on a local computer or on a remote computer, includ
ing running and stopped services.

You can direct Get-Service to get only particular services by specifying the service name or display name of the se
rvices, or you can pipe service objects to Get-Service.


PARAMETERS
-ComputerName
Gets the services running on the specified computers. The default is the local computer.

Type the NetBIOS name, an IP address, or a fully qualified domain name of a remote computer. To specify the loc
al computer, type the computer name, a dot (.), or "localhost".

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Serv
ice even if your computer is not configured to run remote commands.

Required? false
Position? named
Default value Localhost
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-DependentServices []
Gets only the services that depend upon the specified service.

By default, Get-Service gets all services.

Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false

-DisplayName
Specifies the display names of services to be retrieved. Wildcards are permitted. By default, Get-Service gets
all services on the computer.

Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Exclude
Omits the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or
pattern, such as "s*". Wildcards are permitted.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Include
Retrieves only the specified services. The value of this parameter qualifies the Name parameter. Enter a name e
lement or pattern, such as "s*". Wildcards are permitted.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-InputObject
Specifies ServiceController objects representing the services to be retrieved. Enter a variable that contains t
he objects, or type a command or expression that gets the objects. You can also pipe a service object to Get-Se
rvice.

Required? false
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-Name
Specifies the service names of services to be retrieved. Wildcards are permitted. By default, Get-Service gets
all of the services on the computer.

Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? true

-RequiredServices []
Gets only the services that this service requires.

This parameter gets the value of the ServicesDependedOn property of the service. By default, Get-Service gets a
ll services.

Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.ServiceProcess.ServiceController, System.String
You can pipe a service object or a service name to Get-Service.


OUTPUTS
System.ServiceProcess.ServiceController
Get-Service returns objects that represent the services on the computer.


NOTES


You can also refer to Get-Service by its built-in alias, "gsv". For more information, see about_Aliases.

Get-Service can display services only when the current user has permission to see them. If Get-Service 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". The service names
appear in the Name column, and the display names appear in the DisplayName column.

When you sort in ascending order by status value, "Stopped" services appear before "Running" services. The Stat
us property of a service is an enumerated value in which the names of the statuses represent integer values. Th
e 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".


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-service


Description
-----------
This command retrieves all of the services on the system. It behaves as though you typed "get-service *". The defau
lt display shows the status, service name, and display name of each service.





-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-service wmi*


Description
-----------
This command retrieves services with service names that begin with "WMI" (the acronym for Windows Management Instru
mentation).





-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-service -displayname *network*


Description
-----------
This command displays services with a display name that includes the word
"network". Searching the display name finds network-related services even when the service name does not include "N
et", such as xmlprov, the Network Provisioning Service.





-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-service -name win* -exclude winrm


Description
-----------
These commands get only the services with service names that begin with "win", except for the WinRM service.





-------------------------- EXAMPLE 5 --------------------------

C:\PS>get-service | where-object {$_.Status -eq "Running"}


Description
-----------
This command displays only the services that are currently running. It uses the Get-Service cmdlet to get all of th
e services on the computer. The pipeline operator (|) passes the results to the Where-Object cmdlet, which 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, type "get-service | get-member".





-------------------------- EXAMPLE 6 --------------------------

C:\PS>get-service -computername Server02


Description
-----------
This command gets the services on the Server02 remote computer.

Because the ComputerName parameter of Get-Service does not use Windows PowerShell remoting, you can use this parame
ter even if the computer is not configured for remoting in Windows PowerShell.





-------------------------- EXAMPLE 7 --------------------------

C:\PS>get-service | where-object {$_.DependentServices} | format-list -property Name, DependentServices, @{Label="N
oOfDependentS
ervices"; Expression={$_.dependentservices.count}}

Name : AudioEndpointBuilder
DependentServices : {AudioSrv}
NoOfDependentServices : 1

Name : Dhcp
DependentServices : {WinHttpAutoProxySvc}
NoOfDependentServices : 1
...


Description
-----------
These commands list the services on the computer that have dependent services.

The first command uses the Get-Service cmdlet to get the services on the computer. A pipeline operator (|) sends th
e services to the Where-Object cmdlet, which selects the services whose DependentServices property is not null.

Another pipeline operator sends the results to the Format-List cmdlet. The command uses its Property parameter to d
isplay the name of the service, the name of the dependent services, and a calculated property that displays the num
ber of dependent services that each service has.





-------------------------- EXAMPLE 8 --------------------------

C:\PS>C:\PS> get-service s* | sort-object status

Status Name DisplayName
------ ---- -----------
Stopped stisvc Windows Image Acquisition (WIA)
Stopped SwPrv MS Software Shadow Copy Provider
Stopped SysmonLog Performance Logs and Alerts
Running Spooler Print Spooler
Running srservice System Restore Service
Running SSDPSRV SSDP Discovery Service
Running ShellHWDetection Shell Hardware Detection
Running Schedule Task Scheduler
Running SCardSvr Smart Card
Running SamSs Security Accounts Manager
Running SharedAccess Windows Firewall/Internet Connectio...
Running SENS System Event Notification
Running seclogon Secondary Logon

C:\PS> get-service s* | sort-object status -descending

Status Name DisplayName
------ ---- -----------
Running ShellHWDetection Shell Hardware Detection
Running SharedAccess Windows Firewall/Internet Connectio...
Running Spooler Print Spooler
Running SSDPSRV SSDP Discovery Service
Running srservice System Restore Service
Running SCardSvr Smart Card
Running SamSs Security Accounts Manager
Running Schedule Task Scheduler
Running SENS System Event Notification
Running seclogon Secondary Logon
Stopped SysmonLog Performance Logs and Alerts
Stopped SwPrv MS Software Shadow Copy Provider
Stopped stisvc Windows Image Acquisition (WIA)


Description
-----------
This command shows that when you sort services in ascending order by the value of their Status property, stopped se
rvices appear before running services. This happens because the value of Status is an enumeration, in which "Stoppe
d" has a value of "1", and "Running" has a value of 4.

To list running services first, use the Descending parameter of the Sort-Object cmdlet.





-------------------------- EXAMPLE 9 --------------------------

C:\PS>get-service -name winrm -computername localhost, Server01, Server02 | format-table -property MachineName, St
atus, Name, DisplayName -auto

MachineName Status Name DisplayName
------------ ------ ---- -----------
localhost Running WinRM Windows Remote Management (WS-Management)
Server01 Running WinRM Windows Remote Management (WS-Management)
Server02 Running WinRM Windows Remote Management (WS-Management)


Description
-----------
This command uses the Get-Service cmdlet to run a "Get-Service Winrm" command on two remote computers and the local
computer ("localhost").

The Get-Service command runs on the remote computers, and the results are returned to the local computer. A pipelin
e operator (|) sends the results to the Format-Table cmdlet, which formats the services as a table. The Format-Tabl
e command uses the Property parameter to specify the properties displayed in the table, including the MachineName p
roperty.





-------------------------- EXAMPLE 10 --------------------------

C:\PS>get-service winrm -requiredServices


Description
-----------
This command gets the services that the WinRM service requires.

The command returns the value of the ServicesDependedOn property of the service.





-------------------------- EXAMPLE 11 --------------------------

C:\PS>"winrm" | get-service


Description
-----------
This command gets the WinRM service on the local computer. This example shows that you can pipe a service name stri
ng (enclosed in quotation marks) to Get-Service.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113332
Start-Service
Stop-Service
Restart-Service
Resume-Service
Suspend-Service
Set-Service
New-Service