Link to home
Start Free TrialLog in
Avatar of Prashant Girennavar
Prashant GirennavarFlag for India

asked on

AddingTimeout to powershell script

Hello Experts,
I have a script which is getting hung and not able to proceed to next commandline
Below is the script
$ST = new-object -com schedule.service
$Server = "Server1"
$ST.Connect($server)
$M = $ST.GetFolder("\").GetTask("GWSTSAutoPatch")
It gets hung on $ST.GetFolder("\").GetTask("GWSTSAutoPatch") and wont proceed into next command.
Now , question is  , Can I add a timeout on this? so , that script will wait for few sec and it will proceed if it does not get any response.
Thanks,
-Prashant Girennavar.
Avatar of becraig
becraig
Flag of United States of America image

You can use a do - until loop

do {$ST.GetFolder("\").GetTask("GWSTSAutoPatch")
Start-sleep 10}
until ($ST.GetFolder("\").GetTask("GWSTSAutoPatch" = some value; $M = $ST.GetFolder("\").GetTask("GWSTSAutoPatch"))

Open in new window



Something like the above, I've not actually tested what you're trying to do though
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial