Thursday, April 26, 2018

Convert DNS name to IP address in bulk text file

Just really useful script

https://gallery.technet.microsoft.com/scriptcenter/Convert-DNS-name-to-IP-e74f8b01


foreach ($computer in (get-content C:\computers.txt)) { 
  Try{  
    [system.net.Dns]::GetHostAddresses($computer| Foreach-Object { 
      add-content -path C:\computersips.txt -value "$computer,$($_.IPAddressToString)" 
    } 
  } Catch { 
    add-content -path C:\computersips.txt -value "$computer,Cannot resolve hostname" 
  } 
}

No comments:

Post a Comment