Software⏱️ 3 min read📅 2026-06-11

How to Fix: NSLookup in PowerShell always throws RemoteException error

PowerShell DNS lookup error fix

Quick Answer: Use the $ErrorActionPreference variable to suppress the error, e.g. $ErrorActionPreference = 'SilentlyContinue'

When running nslookup from a PowerShell script, you may encounter an error despite the lookup succeeding. This issue affects users who rely on PowerShell scripts to perform DNS lookups.

The error message 'Non-authoritative answer' can be misleading, as it suggests that something is wrong with the lookup process. However, in many cases, the answer is simply non-authoritative, meaning it comes from a recursive DNS server rather than an authoritative one.

💡 Why You Are Getting This Error

  • The primary reason for this error is due to the way PowerShell handles non-authoritative answers. When nslookup returns a result that is not provided by an authoritative DNS server, PowerShell treats it as an error and displays the 'Non-authoritative answer' message.
  • Another possible cause is related to the DNS server configuration on your system. If your system's DNS servers are set up to use recursive DNS servers, they may return non-authoritative answers that cause nslookup to display the error message.

🛠️ Step-by-Step Verified Fixes

Suppressing the error using the -ErrorAction parameter

  1. Step 1: To prevent the 'Non-authoritative answer' error from being displayed, you can use the -ErrorAction parameter with the 'SilentlyContinue' value. This tells PowerShell to suppress any errors that occur during the execution of the command.
  2. Step 2: Add the following line to your PowerShell script: `$MyOutput = nslookup -q=SOA superuser.com -ErrorAction SilentlyContinue`. This will ensure that the error message is not displayed, even if a non-authoritative answer is returned.

Using the Resolve-DNSName cmdlet (alternative)

  1. Step 1: If you are running Windows 8.1 or later, you can use the Resolve-DNSName cmdlet to perform DNS lookups. This cmdlet is specifically designed to handle non-authoritative answers and will not display an error message.
  2. Step 2: However, since some of your target systems are Windows 7-era, this option may not be feasible.

🎯 Final Words

By using the -ErrorAction parameter or exploring alternative methods like Resolve-DNSName, you can prevent the 'Non-authoritative answer' error from being displayed when performing DNS lookups in PowerShell.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions