daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Wait for a DHCP-enabled interface to develop
  2. # a default gateway.
  3. #
  4. # usage: wait-for-network [ <tries> ]
  5. function wait-for-network ($tries) {
  6.         while (1) {
  7.         # Get a list of DHCP-enabled interfaces that have a
  8.         # non-$null DefaultIPGateway property.
  9.                 $x = gwmi -class Win32_NetworkAdapterConfiguration `
  10.                         -filter DHCPEnabled=TRUE |
  11.                                 where { $_.DefaultIPGateway -ne $null }
  12.  
  13.         # If there is (at least) one available, exit the loop.
  14.                 if ( ($x | measure).count -gt 0 ) {
  15.                         break
  16.                 }
  17.  
  18.         # If $tries > 0 and we have tried $tries times without
  19.         # success, throw an exception.
  20.                 if ( $tries -gt 0 -and $try++ -ge $tries ) {
  21.                         throw "Network unavaiable after $try tries."
  22.                 }
  23.  
  24.         # Wait one second.
  25.                 start-sleep -s 1
  26.         }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top