wmic SetDNSSuffixSearchOrder wiithin PowerShell

Welcome Forums General PowerShell Q&A wmic SetDNSSuffixSearchOrder wiithin PowerShell

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #73073

    Topics: 6
    Replies: 11
    Points: 0
    Rank: Member


    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)
    $DNSSuffixes = [string[]]($DNSSuffixes | % {$_.Split(',')} | % {$_.Trim()}) # (This will give the string array data type)

    wmic nicconfig call SetDNSSuffixSearchOrder ($DNSSuffixes)


  • #73085

    Topics: 0
    Replies: 19
    Points: 0
    Rank: Member

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

    Calling 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

    Topics: 6
    Replies: 11
    Points: 0
    Rank: Member

    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.

The topic ‘wmic SetDNSSuffixSearchOrder wiithin PowerShell’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort