1

I have to reset a sequence of services on a group of servers in a certain order. sc.exe is asynchronous, it will return when the service is in the START_PENDING or STOP_PENDING state. Start-Service/Stop-Service will wait for the service to start or stop, but it only works on the local machine, and I don't have remoting enabled in my environment.

Is there an alternative exe or CmdLet to do this? Looks like I'm going to have to use the .NET API.

3 Answers 3

1

Actually, it is possible to use both the Start-Service and Stop-Service PowerShell commands on a remote machine (discussion on this here). I have tested this and confirmed that it works:

Start-Service -inputobject $(get-service -ComputerName SERVER_NAME -Name SERVICE_NAME)

Also, you could try wmic to stop the service. It does appear to wait for the service to stop before continuing, although I have not thoroughly tested this.

wmic /node:"SERVER_NAME" service where name="SERVICE_NAME" call stopservice
4

The PowerShell cmdlets Stop-Service and Start-Service will wait until the services are fully stopped and started respectively.

You can use the -Force switch for Stop-Service to make it also stop services that depend on the service you are trying to stop.

Also if you want to get rid of the Warning message saying the cmdlet is waiting for the service to finish stopping/starting you can add the switch -WarningAction SilentlyContinue.

2
  • I'm I am retarded. However, those seem to be local operations, and I don't want to turn on powershell remoting in this instance. Perhaps I need to revisit my decision not to use powershell remoting. Commented Mar 5, 2012 at 16:27
  • @JustinDearing Oh didn't know you were doing this remotely... Commented Mar 5, 2012 at 19:00
0

They don't have any arguments that allows you to do it synchronously.

You could instead create a while loop that checks whether the service has been started.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .