Monday, 29 December 2014

Start, Stop and Restart Windows Service using Powershell

In Powershell, we have dedicated cmdlets for every operations to manage Windows Services like Start, Stop, Restart and to display information of a Windows Service and you can even easily manage Services from Remote Computer.

Summary:

Start Windows Service using Powershell

You can start a windows service by using Start-Service cmdlet.
Start-Service <service-name> -PassThru
The parameter -PassThru force the command to wait until service started and displays its running status.
Start-Service "RemoteRegistry" -PassThru
Start, Stop and Restart Windows Service using Powershell
If you want to start a service by its display name, you can do it by simply passing display name with the argument -displayname.
Start-Service -displayname <service-display-name> -PassThru
Below command start the RemoteRegistry service by using its -display name "Remote Registry".
Start-Service -displayname "Remote Registry" -PassThru

Stop Windows Service using Powershell

You can stop a windows service by using the Powershell cmdlet Stop-Service.
Stop-Service <service-name> -PassThru
Here, The parameter -PassThru force the command to wait until service stopped and displays status.
Stop-Service "RemoteRegistry" -PassThru

Restart Windows Service using Powershell

You can restart a windows service by using the Powershell cmdlet Restart-Service.
Restart-Service <service-name> -PassThru
Here, the parameter -PassThru force the command to wait until the service get restarted completed and displays its running status.
Restart-Service "RemoteRegistry" -PassThru
Start, Stop and Restart Windows Service using Powershell

Start, Stop and Restart Windows Service in Remote Computer

If you want to start, stop and restart a service in Remote machine, you can do it by using two Powershell cmdlets Get-Service and any one of the manage service cmdlet. First, you can get the windows service object from remote computer by using Get-Service cmdlet and you can do any action like Start,Stop and Restart by using Remote Service object.
Get-Service <service-name> -ComputerName <remote-pc-name> | Start-Service -PassThru
Start the RemoteRegistry service in Win7-PC by using below command:
Get-Service "RemoteRegistry" -ComputerName "Win7-PC" | Start-Service -PassThru
Restart the RemoteRegistry service in Win7-PC by using below command:
Get-Service "RemoteRegistry" -ComputerName "Win7-PC" | Restart-Service -PassThru
Stop the RemoteRegistry service in Win7-PC by using below command:
Get-Service "RemoteRegistry" -ComputerName "Win7-PC" | Stop-Service -PassThru

List all Windows Services and its running status

You can list all the services with display name and running status by using Powershell cmdlet Get-Service.
Get-Service
Start, Stop and Restart Windows Service using Powershell
Pass service name, if you want to get status of a single windows service.
Get-Service "RemoteRegistry"

Advertisements
Advertisements

No comments:

Post a Comment