Hello,
Just asking for some help if there is a way to introduce a way to stop the process if the "Restart-Service" does not complete within 5 seconds.
Reason: On occasion, the Powershell script of restarting services will not complete because the target remote workstation has some issue, which causes the script to hang for awhile (from minutes to hours.) Majority of healthy workstations are able to restart service within 5 seconds.
Ideal: If Restart-Service on target workstation does not complete within 5 seconds, end and move on.
My script excerpt:
If ($IP -like "10*") {
(Restart-Service -InputObject $(Get-Service -Computer $workstation -Name "Print Spooler"))
$Servicerunning = Get-Service -ea 0 -ComputerName $workstation -Servicename "
Print Spooler" | Select-Object -ExpandProperty "Status"
Thanks for anyone's help...