This is another asynchronous approach to a common thing that a system administrator might do, much like a previous article I did on doing a speedy ping with PowerShell and async methods. I’ve already covered performance as well as handling each Task object so that won’t be covered here. Please review the linked blog for more information about those topics.
Instead of a ping, I am going to perform a lookup against DNS for an IP or hostname to get more information about a particular system or systems. The type that I am using to perform the DNS lookups is System.Net.Dns and the methods that I use are GetHostAddressesAsync() and GetHostEntryAsync().
Using both of these allows me to specify either an IPaddress or a hostname to perform the lookup against. Each item passed is tested to see if it is an IP address or not and then passed to the appropriate method that will be called with the data. Once that is done, it is passed to the Task watcher and then when everything has completed, you are presented with the results of each lookup.
The results of the command look something like this:
Get-DNSHostEntryAsync -Computername google.com,prox-hyperv,bing.com, github.com, ` powershellgallery.com, powershell.org,18.104.22.168
If you wanted to make this better, it is out on my GitHub repo so feel free to fork it and submit a PullRequest! Otherwise let me know what you think of it and enjoy!