I have a PowerShell script where I am stopping a Windows service. I, then, wish to wait until the service shows a 'Stopped'
status. I issue the appropriate command to stop the service. I have tried to use a WHILE loop similar to...
While ((Get-Service -Name $ServiceName).Status -ne 'Stopped')
{
Start-Sleep -s 5
}
I have also added a counter to the above WHILE loop that checks the counter to see that it is not over a count of 5. The counter works as it exits the WHILE loop but the service still does not show a status of 'Stopped'
. The service must be stopped before I continue with the remaining code in the script.