Get Public Dns Record Value PowerShell
Nslookup is great, but it’s an old exe tool, and PowerShell is the new way to go. Thanks to .Net, we go the System.Net.dns class, with two methods:
But none of these allow us as much flexibility as nslookup do. You can specify a record type, you can specify which DNS server to use.
If you look at the documentation, you can see that the API is quite easy to use:
Let’s try with a domaon of ours:
We can see a JSON formatted answer, let’s try to use this with PowerShell:
Invoke-WebRequest -Uri "http://www.dns-lg.com/google1/itfordummies.net/txt" | Select-Object -ExpandProperty Content | ConvertFrom-Json | Select-Object -ExpandProperty answer
And voilà !
You can use the API will all of those kind of DNS record types:
I wrote a basic function to use this API with more ease, you can find it on my GitHub repo:
You can load the function without downloading the file with:
Invoke-Expression (Invoke-WebRequest -Uri https://raw.githubusercontent.com/edemilliere/Misc/master/Get-PublicDnsRecord.ps1 | Select-Object -ExpandProperty Content)
You can use it without specifying a node and it will select one randomly from the list available on the API:
You can also choose one, the auto-completion will work on this, and on record type too.
Hereunder an example on how to use the function to check some Office 365 DNS prerequisites: