wmic SetDNSSuffixSearchOrder wiithin PowerShell

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Clum09 Clum09 1 week ago.

  • Author
    Posts
  • #73073
    Profile photo of Clum09
    Clum09
    Participant

    Hello,

    I need to use wmic.exe to set DNS Suffix Search Order on a computer that has a WMI problem using the syntax below:

    wmic nicconfig call SetDNSSuffixSearchOrder ('abc.com','def.com','ghi.com')

    When I ran the above command inside a CMD command prompt window, it worked fine. The output from a successful launch is shown below.
    Executing (Win32_NetworkAdapterConfiguration)->SetDNSSuffixSearchOrder()
    Method execution successful.
    Out Parameters:
    instance of __PARAMETERS
    {
    ReturnValue = 0;
    };

    However, when I launched the same command inside a PowerShell console or script, I kept getting the following error:

    Invalid format.
    Hint: = [, ].

    I tried to reformat the data type of the DNS Suffix Search string to different data type, but I kept getting the same error.
    I know that I can escape the wmic comma parameter with a pair of quotes like ',', but I still cannot figure out how to format the data within the PowerShell console in order for the wmic command to work properly.

    Below is the PowerShell code.

    $DNSSuffixes = 'abc.com','def.com','ghi.com' # (This will give the object array data type)
    or
    $DNSSuffixes = [string[]]($DNSSuffixes | % {$_.Split(',')} | % {$_.Trim()}) # (This will give the string array data type)

    wmic nicconfig call SetDNSSuffixSearchOrder ($DNSSuffixes)

    Thanks.

  • #73085
    Profile photo of Dirk
    Dirk
    Participant

    Here are some good articles on how to run native commands from PowerShell:

    One way that usually works well is providing the arguments as an array:

    $arguments = @('nicconfig','call','SetDNSSuffixSearchOrder',"('abc.com','def.com','ghi.com')")
    wmic $arguments
  • #73090
    Profile photo of Clum09
    Clum09
    Participant

    Your suggestion to use arguments as array works fine.

    I also tried to escape the parentheses ( ) with backtick characters like `($DNSSuffixes`), and that also works.

    Thank you very much for the tips.

You must be logged in to reply to this topic.