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?
There are no dependencies and the code works happily on the 3 other services and everything, on the face of it, looks to be the same.
Just looking for some more in depth knowledge of things it could be that are not currently on the net, just that I’ve googled for many hours and tried all those results that I can find.
I can stop the service using windows, but need this to be automated.
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.
Same error. The code works on 3 out of 4 servers, so there must be something different within the servers (even though they were all built using a standard build process)
Is there are way to get the error to be more meaningful?
Can some diagnostics be added that identifies what is causing the code to break?
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.
Thanks for the idea, but that also suffers the same problem
Adding verbose does not change the message output.
I agree that something within windows must be different, but with I am unable to proceed further without powershell, or the community, providing something that may lead me to understand and then fix.
I can list all the services on the server. I haven’t got any others that I can easily stop to see if the problem is specific to this one service on the specific server.
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.