PowerShell 命令

PowerShell cmdlet

我正在尝试编写一个 PowerShell cmdlet,它接受单个参数的多个输入。

例如,我可以轻松地执行以下操作:

Get-CountryList -Group "a" -Category "x"

但我想做这样的事情:

Get-CountryList -Groups "a b c d" -Category "x"

(或)

Get-CountryList -Groups "a,b,c,d" -Category "x"

我搜索过,但找不到如何执行此操作。

我该怎么做?

您传递的是单个字符串作为参数,但您应该传递 数组 个字符串:

Get-CountryList -Groups "a" -Category "x"
Get-CountryList -Groups "a","b","c","d" -Category "x"

如果需要,您也可以在函数内部进行配置:

Function Get-CountryList {
   Param (
      [String[]]$Groups,
      [String]$Category
   )
   ...
}