Home > Enterprise >  How to pass parameter to type option of nslookup in powershell?
How to pass parameter to type option of nslookup in powershell?

Time:09-27

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?

CodePudding user response:

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
  • Related