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,216.58.218.142
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!
Download Get-DNSHostEntryAsync
https://gallery.technet.microsoft.com/scriptcenter/Get-DNSHostEntryAsync-6fbd006c
Pingback: Performing an Asynchronous DNS Lookup Using PowerShell | Learn Powershell | Achieve More | Soyka's Blog
I have submitted a pull request to GitHub with the proposed fix.
I could be wrong but I think you used the wrong variable for the foreach which would affect the pipeline processing case.
The line in the end block
$Task = ForEach ($Computer in $Computername) {
Should be
$Task = ForEach ($Computer in $Computerlist) {