I am trying to run a script on remote using PowerShell. The script starts a service and works perfectly when I execute it using RDP. I try
PS C:\Users\me> Invoke-Command -ComputerName '123.123.123.123' -Credential $cred -ErrorAction stop -ScriptBlock { Start-Process -FilePath 'C:\someDir\StartService.bat' -Verb RunAs }
I get no error message and the script seems to run, but the service does not start. Any idea?
... -ScriptBlock { C:\someDir\StartService.bat }instead?invoke-command computer1,computer2,computer3 script.ps1Invoke-Command -Session $session ....Start-Process- see this answer). TheNew-PSSessionapproach is only needed if you want to deliberately start a remote process asynchronously and check for completion later (clean up withRemove-PSSessionafterwards).