ShiftNick

Get-ServerDNS

Mar 31st, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #THIS SCRIPT IS UNTESTED
  2.  
  3. $report = ""
  4. $servers = get-content "c:\users\$env:username\Documents\servers.txt"
  5.  
  6. foreach ($server in $servers)
  7.  
  8. {
  9.     $ServerIsUP = Test-Connection -ComputerName $server -Count 3 -Quiet
  10.        
  11.         If ($ServerIsUP -eq $False)
  12.         {
  13.             write-host "$server is not available"
  14.         }
  15.         else
  16.         {
  17.             $addresses = [System.Net.Dns]::GetHostAddresses($server)
  18.                 foreach($a in $addresses)
  19.                     {
  20.                         $report +="{0},{1}`r`n" -f $server,$a.IPAddressToString
  21.                     }#End $Addresses Loop
  22.         }
  23.      
  24.      $report | out-file c:\users\$env:username\Documents\lookup.txt
  25. }
Advertisement
Add Comment
Please, Sign In to add comment