July 14, 2026 Stories worth reading. Perspectives worth sharing.
Resolve IP Addresses from List of Host Names
PowerShell

Resolve IP Addresses from List of Host Names

mo wasay April 25, 2017 1 min read

If you have a list of hostnames/servers that you need IP addresses for its cumbersome to ping each server and get the ip address.

PowerShell to the rescue!

To do this we need a file called Server.txt with each server’s hostname on each line. I am storing the file in D:\Data\Servers.txt.

Once we run the script below it resolves the ip via DNS and stores to another file called D:\Data\Addresses.txt.

[su_note note_color=”#fafae8″]All the IP addresses are getting pulled from their DNS value. [/su_note]

function Get-HostToIP($hostname) {     
    $result = [system.Net.Dns]::GetHostByName($hostname)     
    $result.AddressList | ForEach-Object {$_.IPAddressToString } 
} 
 
Get-Content "D:\Data\Servers.txt" | ForEach-Object {(Get-HostToIP($_)) >> d:\data\Addresses.txt}