wmic SetDNSSuffixSearchOrder wiithin PowerShell


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)


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

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.