4

#PSTip Starting and Stopping services on remote computers

Consider the following PowerShell 2.0 command:

Get-Service -Name wuauserv -ComputerName Server1 | Stop-Service

What do you think is happening here? You get the Windows Update service from Server1 and stop it, right? Wrong!
There’s a bug in PowerShell 2.0 and what actually happens is that Stop-Service stops the service on the local computer.

This has ben fixed in v3 but there’s a trick you can use to make it work in v2, pass the service instance to the InputObject Parameter:

PS> $svc = Get-Service -Name wuauserv -ComputerName Server1
PS> Stop-Service -InputObject $svc
Filed in: Columns, Tips and Tricks Tags: , ,

4 Responses to "#PSTip Starting and Stopping services on remote computers"

  1. Jens Kalski says:

    Why are Bugs in PowerShell are not fixed? This is not only one bug.

  2. ShayLevy says:

    @Jens As mentioned in the tip, it is fixed in v3.

  3. Dan says:

    I have having success with stopping and starting services, however some services can not be found, but I know they are running on the computer. How can I use this for services that might not be in the local path.

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: