Resolve IP Addresses from List of Host Names
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}
Author
Related Posts
Adding an Application Registration\ Service Principal to another Application Registration\ Service Principal
Typically when working with App Roles in Azure Active Directory for a single application registration or service principal and then self consuming...
Read out all
Get all the domains controllers in the AD forest along with their current FSMO roles
In a large enterprise an admin would need to keep track of all the domains in a AD forest, the domain names,...
Read out all
Get Inactive Users Report for the past 60 days in a multi domain environment
I had a request recently to provide an inactive user report for the past 60 days. Basically, find out which accounts have...
Get Primary, Secondary, Tertiary DNS values and more from Multiple Servers
Came across a unique request to get primary, secondary, and tertiary DNS values for multiple computers/servers across the domain. I started writing...
Fix Active Directory broken security inheritance problem
Ran into a situation at a client location where in Active Directory, the security permissions applied to an OU were not getting...
Get All DCs in the Entire Forest
Getting a know a new environment for a new client and I a quickly needed information about all domain controllers in the...
Read out all