brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Resolve-DnsName is the PowerShell way to ask a specific DNS server

Windows
~/tips/tip-windows-resolve-dnsname

Resolve-DnsName example.com -Type MX -Server 1.1.1.1

Looks up DNS records from PowerShell, with the record type and DNS server you choose.

On Windows I used to reach for nslookup out of habit. In PowerShell, Resolve-DnsName does the same job and gives you objects you can filter, which suits me better.

Resolve-DnsName example.com -Type MX -Server 1.1.1.1

-Type picks the record type: A, AAAA, MX, TXT, CNAME and so on. Without it you get A and AAAA. -Server sends the question to a DNS server of your choice instead of the one your network adapter uses. That makes it easy to compare what your Pi-hole or router says with what a public resolver says.

Two switches I find useful when something does not add up:

Resolve-DnsName nas.local -NoHostsFile
Resolve-DnsName intranet -DnsOnly

-NoHostsFile skips the hosts file, so an old entry there cannot fool you. -DnsOnly uses only DNS and leaves LLMNR and NetBIOS out, which helps when a short name resolves on your LAN and you want to know whether DNS had anything to do with it.

Because the output is objects, you can pipe it into Format-Table or Where-Object like any other PowerShell result, which plain nslookup text never allowed.

Caveat: it comes from the Windows DnsClient module, so a script that uses it is a Windows script. On a Mac or Linux box I’d use dig for the same job.

Further reading: Resolve-DnsName on Microsoft Learn

More Windows tips winget show --id Git.Git Win+Ctrl+C Win+Shift+Left arrow Win+Ctrl+Left arrow Win+1 … Win+9 All Windows tips (87) All topics

Link