Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Stop-Service/Start-Service not working on a specific server

I have three servers, let's call them Deploy1, Deploy2, Target. All servers are running Windows Server 2008R2, fully updated. A domain user, admin1, is configured as administrator on all servers, and this is the user I'm running all the commands with.

The following command works on Deploy1:

Get-Service "MyService" -ComputerName Target | Stop-Service

When running the same command on Deploy2, the command fails with the following message:

Cannot find any service with service name 'MyService'.

On Deploy2, the following command works, and displays the service and its status.

Get-Service "MyService" -ComputerName Target

Now, I know there are other ways to stop/start services via PowerShell, but I like this one as it automatically waits for the server to actually stop/start.

So what could be wrong with Deploy2?

like image 967
Doron Yaacoby Avatar asked Jan 26 '26 09:01

Doron Yaacoby


1 Answers

Powershell v2.0 has a bug (feature?) in how the object returned by Get-Service is implemented. It does not actually set the ComputerName property correctly. Because of this, it can only affect local services. If you upgrade to Windows Management Framework 3.0 (and consequently Powershell v3) the bug is fixed and will work correctly.

like image 143
Matthew Brubaker Avatar answered Jan 29 '26 11:01

Matthew Brubaker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!