Multi-Value Parameter Defaults

Welcome Forums General PowerShell Q&A Multi-Value Parameter Defaults

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

3 years ago.

  • Author
  • #33636

    Points: 0
    Rank: Member

    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 {
       param (
          [string[]]$DNSServers = '', ''

    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.

  • #33637

    Points: 38
    Rank: Member

    Try it like this:

    [string[]]$DNSServers = @('','')

    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 [].

  • #33638

    Points: 0
    Rank: Member

    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).

  • #33639

    Points: 0
    Rank: Member

    Great that worked.. Thank you Matt and Dave

The topic ‘Multi-Value Parameter Defaults’ is closed to new replies.