Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement