I was wondering if anyone could help me out with this. I have this statement to stop a service but at times the service sometimes doesn't stop due to dependencies so i added a 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 #keep repeating stop services every 5 seconds until all services have stopped
}
I want to add a counter to stop the loop after 60 seconds and if the service is still running then to write-host
rn "Service not stopped."
Any help is appreciated. Thanks all.