Using the Get-Service Cmdlet
Listing Service Information
This will probably shock you, but - just in case - you better sit down: the Get-Service cmdlet is designed to retrieve information about the services installed on your computer. (And to think that some people say Windows PowerShell is too complicated!) Do you want information about all the services installed on your computer? Then just call Get-Service without any additional parameters:
Get-Service
Here’s the kind of information you’ll get back:
Status Name DisplayName
------ ---- -----------
Running AdobeActiveFile... Adobe Active File Monitor V4
Stopped Alerter Alerter
Running ALG Application Layer Gateway Service
Stopped AppMgmt Application Management
Running ASChannel Local Communication Channel
Alternatively, you can take advantage of the Windows PowerShell filtering capabilities to return just a subset of the services installed on your computer. For example, this command takes the data returned by Get-Service and pipes it through the Where-Object cmdlet. In turn, Where-Object filters out everything except those services that are stopped:
Get-Service | Where-Object {$_.status -eq "stopped"}
In the preceding command, the $_. represents the object passed across the pipeline (that is, the collection of services and their properties), while status is simply the service property we want to filter on. And because we’re interested only in services that are stopped, we use the syntax -eq “stopped”. What if we were interested only in services that were running? In that case, we’d use this command:
Get-Service | Where-Object {$_.status -eq "running"}
So what kind of data will we get back when we request only services that are currently stopped? This kind of data:
Status Name DisplayName
------ ---- -----------
Stopped Alerter Alerter
Stopped AppMgmt Application Management
Stopped aspnet_state ASP.NET State Service
Stopped BITS Background Intelligent Transfer Ser...
Stopped Browser Computer Browser
By default Windows PowerShell returns services sorted in alphabetical order. By using the Sort-Object cmdlet, however, you can sort that returned data any way you want. For example, this command sorts services first by Status, and then by DisplayName:
Get-Service | Sort-Object status,displayname
Get-Service Aliases |
---|
|