在 Azure Automation Powershell 脚本中使用参数数组
Using parameter array in Azure Automation Powershell script
对于一个函数,我想使用 DayOfWeek
数组从自动化脚本中排除某些日期。为此,我设置了以下功能:
Param
(
[Parameter (Mandatory= $true)]
[ValidateNotNullOrEmpty()]
[DayofWeek[]] $ExcludeDays
)
foreach ($ExcludeDay in $ExcludeDays)
{
Write-Output $ExcludeDay
}
在 Azure 测试窗格中,我包含了如下数组:
这是错误 returns:
Failed
Cannot process argument transformation on parameter 'ExcludeDays'. Cannot convert value "Monday, Friday, Saturday" to type "System.DayOfWeek[]".
我已经在 Powershell 中进行了类似的尝试,方法是创建一个函数,该函数采用相同的参数数组并且没有类似输入的问题。有人知道如何让它工作吗?
您应该将它们传递为 ['Monday','Friday','Saturday']
。
您应该将它们作为 ['Monday','Friday','Saturday']
传递。正如乔伊回答的那样
另一种解决方案是输入为
周一、周二、周三
然后拆分。
$CharArray = $InputString.Split(",")
对于一个函数,我想使用 DayOfWeek
数组从自动化脚本中排除某些日期。为此,我设置了以下功能:
Param
(
[Parameter (Mandatory= $true)]
[ValidateNotNullOrEmpty()]
[DayofWeek[]] $ExcludeDays
)
foreach ($ExcludeDay in $ExcludeDays)
{
Write-Output $ExcludeDay
}
在 Azure 测试窗格中,我包含了如下数组:
这是错误 returns:
Failed
Cannot process argument transformation on parameter 'ExcludeDays'. Cannot convert value "Monday, Friday, Saturday" to type "System.DayOfWeek[]".
我已经在 Powershell 中进行了类似的尝试,方法是创建一个函数,该函数采用相同的参数数组并且没有类似输入的问题。有人知道如何让它工作吗?
您应该将它们传递为 ['Monday','Friday','Saturday']
。
您应该将它们作为 ['Monday','Friday','Saturday']
传递。正如乔伊回答的那样
另一种解决方案是输入为 周一、周二、周三
然后拆分。
$CharArray = $InputString.Split(",")