5

#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: , ,
© 2018 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: