2

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?

1
  • 1
    I reckon that's because what's being passed in is actually a [string]. You should change your parameter definition to match the incoming type and then perform the parsing/conversion in the body of your function e.g. $ExcludeDaysString -split "," Commented Jul 15, 2019 at 7:13

2 Answers 2

5

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

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(",")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.