Using PowerShell to bulk look up DNS for domain names
Created a script this evening to bulk look up DNS information. By using the cmdlet Resolve-DnsName
feeded with a list of domains from a text file, and using the ConvertTo-AceEncoding
function from a previous post to be able to resolve IDN (International Domain Name) domains. This ended up with the script below, let’s take a look.
To start with I created an advanced function with two parameters. The $Type
parameter lets you specify what kind of DNS records you want to resolve, where I specified A records as default value. The$Path
parameter is the path to where the list of domains is stored, I specified that the default list is stored in the C:\temp folder, since it’s often a one time lookup and not critical that the list is removed.
The next step, process
the block.
In the process
block I’m using the Get-Content
cmdlet to collect the content from the $File
parameter and store it in the variable $DomainList.
Then I’m creating the function ConvertTo-AceEncoding
, which is called later within the foreach
loop. The function converts IDN (International Domain Names) to ACE encoded format (Punycode). For instance the domain krøllalfa.no
is an IDN domain using Norwegian characters like "æøå", the result from the function is that alfakrøll.no
gets converted into xn--krllalfa-64a.no
.
You will notice that I added Write-Verbose
messages that is used to debug and view the each step when the script is running. Without the messages the script will become a lot smaller. I added a script without the messages in the end.
Further on I loop through all the elements in the $DomainList
and check if the domain name contains Norwegian special characters by calling the function ConvertTo-AceEncoding
, then stores the domains to the file ConvertedDomainList.txt
, and for domains that doesn't contains special characters gets appended to the same ConvertedDomainList.txt.
In the last section of the process block I’m using Get-Content
to collect all converted domains and storing the result in the variable $Domains.
Then I’m looping through all domains in $Domains
and piping it to the Resolve-DnsName
cmdlet, then I'm selecting the properties I needed, then formatting the list to be more readable with Format-List
.
Finally, the $EmptyFile
variable is just an variable to empty the ConvertedDomainList.txt
list to get a clean start for each time the script runs.
To run the script:
Remember to create the file C:\tempDomainList.txt
and fill it with some domains. I used some domains from this GitHub repo https://github.com/opendns/public-domain-lists/blob/master/opendns-top-domains.txt to have something to test on.
The result after running the script with default values, Resolve-BulkDnsName.

And, the result after running with the default values and with the switch, Resolve-BulkDnsName -Verbose

I think that is about it, a little useful and fun project for bulk resolving domain names. Comes in handy when you need to look up the A, CNAME or nameserver records for each domain. Have I found out. Below is the full script, with Write-Verbose
and without.
With Write-Verbose.
Without Write-Verbose.
Have a great Easter, enjoy!
Originally published at https://www.fredrikengseth.com.