I have a network wherein CNAME entries are created for some servers and not for others. How can I get the details for server names alone by executing Resolve-DnsName script?
If I try
$servername = Resolve-DnsName -Name webserver.999.com
Write-Host $servername.Name
I get 2 results one with webserver.999.com and another with the actual server name post resolving the DNS for servers with CNAME, but only the server name where CNAME entry is not present. I am looking for a solution wherein the command catches the result with only the server name.
Select the result that is an A record:
Resolve-DnsName -Name foo.example.com |
Where-Object { $_.QueryType -eq 'A' } |
Select-Object -Expand Name
To turn a CNAME into the original hostname:
Resolve-DnsName 'webserver.999.com' -Type CNAME |
Select-Object -ExpandProperty 'NameHost'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With