When I run nslookup from a PowerShell script, I always get an error (which is output to the console) despite the fact the lookup succeeds:
PS C:\Windows\system32> $MyOutput = nslookup -q=SOA superuser.com
8.8.4.4 nslookup : Non-authoritative answer: At line:1 char:13
+ $MyOutput = nslookup -q=SOA superuser.com 8.8.4.4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Non-authoritative answer::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
This seems to be caused by the fact the answer is non-authoritative. Doing a lookup against an authoritative DNS server doesn't return an error.
In my attempts to find a solution myself, I found this SO answer. It suggests using the Resolve-DNSName command. Unfortunately that requires Windows 8.1/Server 2012 R2 and some of the systems my script will run on are Windows 7-era.
How can I prevent this error from being displayed?
Bonus points for explaining why PowerShell thinks an error has occurred!