How to pass parameter to type option of nslookup in powershell?

126 Views Asked by At

Here I want to run nslookup with specified types of DNS records in PowerShell. I tried it by define the types of DNS records and run nslookup with Foreach.

$types = @("soa", "a")

Foreach ($type in $types){
    nslookup -type=$type google.com
}

But this doesn't seem to work because $type is not recognized as a parameter.

Does anyone know how to solve this problem?

1

There are 1 best solutions below

0
Mathias R. Jessen On BEST ANSWER

Quote the whole argument, including the parameter name, with double-quotes - this will prevent PowerShell from interpreting -type as a managed parameter:

nslookup "-type=$type" google.com