Windows Administrator Basics: Managing Windows Services from Powershell

This is the third article of  'Windows Administrator Basics : Windows Services" series. In this series we will learn to manage Windows services from Powershell. If you have not read previous articles then follow below links to navigate through them.

Part1: Windows Administrator Basics: Windows Services
Part2: Windows Administrator Basics: Managing Windows services from command line

Get status of a service using Get-Service cmdlets

The Get-Service cmdlets allow you to list services on local computer.

ExamplesList all services on the computer
PowerShell
PS C:\> Get-Service

Status   Name               DisplayName                           
------   ----               -----------                           
Running  AdobeARMservice    Adobe Acrobat Update Service          
Stopped  AJRouter           AllJoyn Router Service                
Stopped  ALG                Application Layer Gateway Service     
Stopped  AppReadiness       App Readiness                         
Stopped  BDESVC             BitLocker Drive Encryption Service    




ExamplesList all services which match a search string
PowerShell
PS C:\> Get-Service -DisplayName "*Application*"

Status     Name                 DisplayName                           
------       ----                     -----------                           
Stopped  ALG                  Application Layer Gateway Service     
Stopped  AppIDSvc         Application Identity                  
Running  Appinfo            Application Information               
Stopped  AppMgmt          Application Management  
Stopped  COMSysApp     COM+ System Application   


ExamplesList all Running Services
PowerShell
PS C:\> Get-Service | Where-Object {$_.Status -eq "Running"}


Status   Name               DisplayName                           
------   ----               -----------                           
Running  AdobeARMservice    Adobe Acrobat Update Service          
Running  Appinfo            Application Information               
Running  AppXSvc            AppX Deployment Service (AppXSVC)     
Running  aswbIDSAgent       aswbIDSAgent                          
Running  AudioEndpointBu... Windows Audio Endpoint Builder        


ExamplesGet status of specific service
PowerShell
PS C:\> Get-Service -Name BITS




  


ExamplesGet status of specific service on Remote Computer

To get the status of a service on remote computer you just need to add -ComputerName parameter
PowerShell
PS C:\> Get-Service -ComputerName Desktop-9OP8RCA -Name BITS

Status   Name               DisplayName                           
------   ----               -----------                           
Running  BITS               Background Intelligent Transfer Ser...   




Start and Stop service using Start-Service and Stop-Service cmdlets

As name suggest, the Stop-Service cmdlets allow you to stop a service while Start-Service cmdlets allow you to start a service. The below examples show usage of both cmdlets to start / stop service on local or remote computer.

ExamplesStop a service
PowerShell
PS C:\> Stop-Service -Name BITS 

Another way is to get a service using Get-Service cmdlets and then pass the output to Stop-Service cmdlets using Piping.
PowerShell
PS C:\> Get-Service -Name BITS | Stop-Service





The benefits of using second methods is that it support remote services as well. While Get-Service cmdlet support remote services, Start-Service and Stop-Service cmdlets do not. However, the result can be achieved by usage of Piping.

See the below example to understand how Piping was used to start and stop a service on remote computer 





You can download offline copy of this article ebook from Techuisitive store.




Comments

Popular posts from this blog

SCCM Software Distribution Troubleshooting

Powershell - List AD Organizational Unit and GPOs linked to them

Troubleshooting System Center Endpoint Protection (SCEP) Client