August 29, 2015

PowerShell - Services

PowerShell provides good support for managing windows services. You can list down, start, stop the services from shell. Lets start:

This command will give you the avialable cmdlets for managing services:
Get-Command *service* | Where-Object {$_.CommandType -eq 'cmdlet'}

Get-Service                                                                          
New-Service                                                                          
Restart-Service                                                                      
Resume-Service                                                                       
Set-Service                                                                          
Start-Service                                                                        
Stop-Service                                                                         
Suspend-Service                                                                      

List all services beginning with "sql":
Get-service sql*

This command will give you only running services beginning with "sql":
Get-Service sql* | Where-Object { $_.status -eq 'Running' }

Lets try to start 'SQL Server Browser' service
Get-Service | Where-Object { $_.DisplayName -eq 'SQL Server Browser' } | Start-Service

You need administrator rights to run this command.

In-case you get this error:
SQL Server Browser (SQLBrowser)' cannot be started  due to the following error: Cannot start service SQLBrowser on computer '.'.
Please refer to this post:
http://idreesdotnet.blogspot.com/2015/08/powershell-start-service-service-x.html


All these cmdlets needs you to have administrator rights.
  • New-Service                                                                          
  • Restart-Service                                                                      
  • Resume-Service                                                                       
  • Set-Service                                                                          
  • Start-Service                                                                        
  • Stop-Service                                                                         
  • Suspend-Service                                                                      

No comments:

Post a Comment