在Azure Automation Powershell脚本中使用参数数组

时间:2019-07-15 06:48:29

标签: azure powershell parameters azure-automation

对于一个函数,我想使用DayOfWeek数组从自动化脚本中排除某些日子。为此,我设置了以下功能:

Param
(
    [Parameter (Mandatory= $true)]
    [ValidateNotNullOrEmpty()]
    [DayofWeek[]] $ExcludeDays
)

foreach ($ExcludeDay in $ExcludeDays)
{
    Write-Output $ExcludeDay
}

在Azure测试窗格中,我包括以下数组:

Input example

这是它返回的错误:

Failed
Cannot process argument transformation on parameter 'ExcludeDays'. Cannot convert value "Monday, Friday, Saturday" to type "System.DayOfWeek[]".

我已经在Powershell中通过创建一个采用相同参数数组并且对相似输入没有问题的函数进行了类似的尝试。有人知道如何使它工作吗?

2 个答案:

答案 0 :(得分:1)

您应将它们作为['Monday','Friday','Saturday']传递。

enter image description here

答案 1 :(得分:0)

您应将它们作为['Monday','Friday','Saturday']传递。正如乔伊回答

另一个解决方案将被输入为 星期一,星期二,星期三

并将其拆分。

$ CharArray = $ InputString.Split(“,”)