NotFound
NotFound

Reputation: 6157

Using parameter array in Azure Automation Powershell script

For a function I want to use an array of DayOfWeek to exclude certain days from the automation script. For that I've setup the following function:

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

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

In the Azure testpane I've included the array as follows:

Input example

and this is the error it returns:

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

I've tried it simularly in Powershell by creating a function that takes the same parameter array and had no issue with similar input. Anybody knows how to get it working?

Upvotes: 1

Views: 4393

Answers (2)

Blue Clouds
Blue Clouds

Reputation: 8151

You should pass them as ['Monday','Friday','Saturday']. as Joy answered

another solution would be get input as Monday,Tuesday,Wednesday

and split it.

$CharArray = $InputString.Split(",")

Upvotes: 1

Joy Wang
Joy Wang

Reputation: 42053

You should pass them as ['Monday','Friday','Saturday'].

enter image description here

Upvotes: 4

Related Questions