1

It's a long story, but I need to create a SQL trigger that executes a script remotely which executes another script remotely (yeah, I know). I'm using PowerShell.

I have started at the end:

Get-Service –Name “service” –ComputerName “Server2” | Set-service –Status Stopped

Get-Service –Name “service” –ComputerName “Server2” | Set-service –Status Running

This works just fine. Then, the script that will be executed on the trigger:

Invoke-Command –computername “cluster” –command {d:\adminscripts\RestartServer2Service.ps1}    

(yes, I use a NLB cluster, and it's reading the script)
But, I get this:

Cannot find any service with service name ‘service’.

Any thoughts? Any help will be appreciated. Thanks

  • Right off the top of my head, service names are case sensitive. Is this service actually named "service"? or maybe "Service"? In fact, are you sure it's even named "service"? – Get-HomeByFiveOClock Oct 14 '14 at 13:41
  • Thanks for trying ehhe. But the name it's ok. The first script (those two lines), which it's restartServer2Service.ps1 works fine. It's only when i use the invoke-command when it does not. – Horaceman Oct 14 '14 at 13:48
0

This is almost certainly a two-hop issue. If I use Enter-PSSession to connect to ServerA, and then run Get-Service spooler -ComputerName ServerB, I get the exact same "cannot find any service with service name" error.

However, if I run Enter-PSSession ServerA -Authentication CredSSP -Credential (Get-Credential), then the Get-Service command runs fine.

The problem is the second hop -- going from the first remote computer to the second (and third); it's a "bridge too far" for the default authentication protocol used by PS remoting. The solution that I use for this sort of problem is CredSSP.

You can find more details about the problem and how to enable/use CredSSP in this Scripting Guy article.

  • I finally ended up doing something to avoid it, because my first hop could call itself and the server/client thing was chaotic. But you were right. Thanks. – Horaceman Oct 20 '14 at 16:53
1

-command is not a valid parameter for Invoke-Command. Use -FilePath instead to trigger your second script.
Also, ensure you have the proper credentials to execute these scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.