25

In Linux, I would use dig to specify a DNS server of 127.0.0.1 with the following command:

dig google.com @127.0.0.1

I installed Bind tools for windows (choco install bind-toolsonly). How can I run that same command? I get the following error:

PS C:\Users\jhilden> dig google.com @127.0.0.1
At line:1 char:21
+ dig google.com @127.0.0.1
+                     ~
Missing property name after reference operator.
At line:1 char:16
+ dig google.com @127.0.0.1
+                ~~~~
The splatting operator '@' cannot be used to reference variables in an
expression. '@127' can be used only as an argument to a command. To
reference variables in an expression use '$127'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingPropertyName
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
jhilden
  • 12,207
  • 5
  • 53
  • 76

3 Answers3

74

I know this answer doesn't use Bind tools, as you inferred in your question. That said, however, PowerShell comes with the Resolve-DnsName to perform this task. I believe that the following command will do what you are after

Resolve-DnsName -Name google.com -Server 127.0.0.1
shawmanz32na
  • 1,260
  • 3
  • 15
  • 19
  • 1
    @r590 Upon investigation, it appears that `Resolve-DnsName` was added in PowerShell 3.0, so is only available on Windows 8+ / Windows Server 2012+_ – shawmanz32na Mar 27 '18 at 19:42
  • 2
    note that WMF 5.1 (which includes PowerShell 5.1) has been back-ported to Windows 7 SP1 - so anything W7SP1, Server 2008R2SP1 or later should be able to run a full set of PowerShell commands. – unbob Apr 08 '18 at 19:56
  • This does not support a `port`. Any other possibilities? – Alex Aug 22 '18 at 02:40
  • 1
    [Reference doc](https://learn.microsoft.com/en-us/powershell/module/dnsclient/resolve-dnsname?view=windowsserver2019-ps) – Efren Apr 12 '21 at 07:52
16

Like the error message says: the @ has a special meaning in PowerShell. Escape the character

dig google.com `@127.0.0.1

or put the argument in quotes

dig google.com "@127.0.0.1"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
-3

I think your parameters are backwards. Server should come first.

Curt Evans
  • 346
  • 2
  • 4