Using PowerShell to bulk look up DNS for domain names

Fredrik Engseth
3 min readOct 9, 2021

--

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$Pathparameter 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, processthe block.

In the processblock 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 foreachloop. 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 $Domainsand 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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Fredrik Engseth
Fredrik Engseth

Written by Fredrik Engseth

Developer | Dynamics 365 | Power Platform | Azure | Personal development | Investments | ☕ https://www.buymeacoffee.com/fredrikengseth

No responses yet

Write a response