I was wondering if anyone could help me with this. I have this statement to stop the service, but sometimes the service sometimes does not stop due to dependencies, so I added start-sleep -s 5.
while($module | Get-Service | ? {$_.Status -eq "Running" -or $_.Status -eq "Stopping"})
{
set-service $module -ComputerName $targetserver -StartupType Disabled -Status Stopped -PassThru
;
Start-Sleep -Seconds 5
}
I want to add a counter to stop the loop after 60 seconds, and if the service is still running, then write-hostrn "Service not stopped."
Any help is appreciated. Thanks to everyone.
source
share