Advertisement
Guest User

Ping DHCP Range of IP Addresses with a Variable

a guest
Jan 9th, 2014
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This Powershell script is used to ping a set range of IP address with a variable in the address.
  2. #
  3. # Based on the input the user will ping all IP addresses in the range of 10.2.X.200 through 10.2.X.210.
  4. # This just happens to be the range of IP addresses we allow for DHCP at our locations.
  5. # For my purposes at my workplace the Plant # corresponds to the 3rd byte of an IP Address (the variable here).
  6. # This can be altered to fit your needs.
  7. #
  8. # This script is also written to be ran from a shortcut.
  9.  
  10. write-host "This Script will Ping IP Addresses .200 through .210
  11. and look for connectivity at a given Plant." -BackgroundColor Gray -ForegroundColor Blue
  12.  
  13. write-host ""
  14.  
  15. $plant = Read-Host 'What Plant will we be testing? (Please enter a numeric value)'
  16.  
  17. write-host ""
  18.  
  19. $servers = "10.2.$plant.200","10.2.$plant.201","10.2.$plant.202","10.2.$plant.203","10.2.$plant.204","10.2.$plant.205","10.2.$plant.206","10.2.$plant.207","10.2.$plant.208","10.2.$plant.209","10.2.$plant.210"
  20.  
  21. Foreach($s in $servers)
  22.  
  23. {
  24.  
  25.   if(!(Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet))
  26.  
  27.   {
  28.  
  29.    write-host "Problem communicating with $s" -foregroundcolor "yellow"
  30.  
  31.      if(!(Test-Connection -Cn $s -BufferSize 16 -Count 1 -ea 0 -quiet))
  32.  
  33.       {write-host "No device detected at $s" -foregroundcolor "red"}
  34.  
  35.        ELSE {write-host "Resolved problem connecting to $s" -foregroundcolor "green"} #end if
  36.  
  37.    } # end if
  38.  
  39.    ELSE {write-host "Device successfully detected at $s" -foregroundcolor "green"} #end foreach
  40.  
  41. } # end foreach
  42.  
  43. write-host "End of Script." -BackgroundColor Black -ForegroundColor Black
  44. Start-Sleep -s 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement