Resolve-DNSName errors for single label names

TechUser2020-6505 251 Reputation points
2021-11-04T12:43:26.62+00:00

Hi,
I'm writing a DNS test script to validate DNS functionality post-migration from one DNS platform to another. I'm hitting a couple of issues with the script:

  1. Resolve-DnsNames fails with single-label names, e.g. "Resolve-DnsName server1 -DnsOnly" returns Dns name doesn't exist. Resolve-DnsName with the FQDN works as expected. Nslookup works fine with the single-label name. Is there a way to get Resolve-DnsName working with only single label names?

I've tried using nslookup instead, however it throws errors for non-authoritative answers and I've struggled to catch the errors (they don't seem to caugh with a try catch block).

Advice appreciated.

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,355 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. SChalakov 10,261 Reputation points MVP
    2021-11-04T14:04:56.963+00:00

    Hi,

    I don't think Resolve-DNSName works with Single Label Domain Names. It does resolve NetBIOS names if you use the proper switch, but not SLDNs.

    What I found though is this, which might help you work your way around Resolve-DNSNAme by using nslookup or one of the other methods and also catch errors in your script. There are also some nice examples, which might get you started:

    Finding Non-Resolveable IP Addresses
    https://tommymaynard.com/tag/resolve-dnsname/

    Please let me know if it was really helpfull, thanks in advance!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Regards,
    Stoyan

    0 comments No comments

  2. Rich Matheisen 44,621 Reputation points
    2021-11-04T14:12:39.833+00:00

    Try using this instead:

    [System.Net.Dns]::GetHostAddresses("yourhosthere")
    
    0 comments No comments

  3. Limitless Technology 39,336 Reputation points
    2021-11-04T19:34:51.207+00:00

    Hello @TechUser2020-6505

    This can't be achieved with Resolve-DnsName as it needs to have the FQDN to query the right domain and avoid conflicts. Examples: https://learn.microsoft.com/en-us/powershell/module/dnsclient/resolve-dnsname?view=windowsserver2019-ps

    Hope this helps with your query,

    --------
    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  4. Evgenij Smirnov 541 Reputation points
    2021-11-05T11:07:42.673+00:00

    Resolve-DNSName with -DNSOnly switch will only query the DNS server for the exact string you're entering. Short of having a GlobalNames zone, there's no way DNS can answer that because it needs a way to determine the zone where to look up in the first place.

    nslookup with default settings will use your suffix search list. If you set the nslookup options nosearch and nodefname you will get the same behaviour.

    0 comments No comments