Multi-Value Parameter Defaults

I would like to know if there is a way to assign more than one value to a parameter definition in and advanced function

 
function set-networkinfo {
   [CmdLetBinding()]

   param (
      
      [Parameter()]
      [string[]]$DNSServers = '1.1.1.1', '2.2.2.2'

   )

}

I know this throws and invalid expression assignment and I can possibly separate into two distinct parameters with one value each. But I am just curious if this is even possible.

Try it like this:

[string]$DNSServers = @(‘1.1.1.1’,‘2.2.2.2’)

The @() is called the array operator and is used to create an array of objects. Your parameter definition accepts an array of strings as denoted by the .

You don’t always have to use the @() operator to create arrays, but in this case, it’s necessary to help the PowerShell parser know what’s going on (because you normally have a comma separating parameters in the param block).

Great that worked… Thank you Matt and Dave