I have a script that is trying to restart and service on a server. the script works on 3 out of 4 servers
I am running the script manually - for testing- as administrator with executionpolicy unrestricted.
The error message is cannot be stopped due to the following error: Cannot stop XXXX service on computer ‘.’
All 4 servers are configured in the same way - at least a far as can be known
Need some ideas on what the problem might be and what the fix is.
There is no additional context in the error message aside from cannot stop the service? Likely there is a processes that is hung up and there is a timeout occuring. Is there anything in the event logs?
The service exists on 4 servers, the code works on 3 of the 4, but not the forth. There is some, currently unknown, difference between the machines that I am hoping someone may be able to provide some information on that will help resolve my problem.
This looks like a windows issue and not powershell but you can try:
Restart-Service -Name “ccmexec” -Verbose
Verbose usually shows more info about errors or completions.
Let us know what the output of the verbose is.
Als you can try this:
$Computer = “SERVER1” #change to your server4
$ServiceName = “ccmexec” #change to your service you want to restart
$Service = Get-Service -Name $ServiceName -ComputerName $Computer
Restart-Service -InputObj $Service -ErrorAction stop
Last and mostly:
Learn to use New-PsSession, this should always work when connecting to a remote machine.
As long winrm is working.
The account you are running is allowed to remote powershell because you can get all services.
01.) Did you start powershell as admin when running the restart-service?
02.) Check the account that runs the service, use those credentials to restart the service via Invoke-Command.
03.) Just to be sure, give us the result from Get-ExecutionPolicy.