powershell - how do I time a command so not greater then 30secs -


i wrote below code works fine - sets each network card enabled (and waits until card has $statusconnected=2).

the problem see when roll out production on servers there dodgy servers whereby not able change status 2 , loop forever in trying 2.

any 1 know how can put timer on below if not change 2 in 30seconds move onto next card? handy if show me card failed on.

do add do , put timer -gt 30 ? - not sure how start on ideas useful - plus, hard test lab servers work fine in enabling nics.

$listofnics = get-wmiobject -class win32_networkadapter -computername . -filter "name '%hp%' or name '%broadcom%' or name '%intel%'" $statusconnected = $listofnics.netconnectionstatus  foreach ($disnics in $listofnics)      {          {             $disnics.enable()             }         until($statusconnected -eq "2")                 } 

i'd grab time , compare in loop condition.

foreach ($disnics in $listofnics)      {         $starttime = get-date;          {             $disnics.enable()             }         until(($statusconnected -eq "2") -or (((get-date) - $starttime).totalseconds -gt 30))      } 

note: had seconds here instead of totalseconds. want totalseconds. seconds second component, if it's 5 hours 4 minutes , 13 seconds, seconds 13, while totalseconds 18253.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -