I have an advanced function I have been working on that looks something like this:
{Function Do-Something { [cmdletbinding()] Param ( [Parameter(Mandatory=$true, [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)] [string[]]$Param1, [Parameter(Mandatory=$true, [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)] [string[]]$Param2, [Parameter(Mandatory=$true, [ValidateSet('Yes', 'No', 'Y', 'N', IgnoreCase = $true)] [string[]]$Param3 ) Begin {} Process { } }}
My question is, how do I get the values such as “Yes”, “Y”, “No”, and “N” that’s located in the [ValidateSet()] validation attribute processed correctly without having to use multiple “If” and “ElseIf” statements.
For instance, I want to avoid the following, because I know there is a faster and more efficient way (less typing) to do it:
If ($param1 -match “Yes” -or “Y” -and $param2 -match “Yes” -or “Y” -and $param3 -match “Yes” -or “Y”)
{
#Do something here
}
ElseIf ($param1 -match “No” -or “N” -and $param2 -match “Yes” -or “Y” -and $param3 -match “Yes” -or “Y”)
{
#Do something
}
I was reading that splatting may help me here, but I am new to the splatting technique and need some help with this one.
I appreciate any help that anyone can offer.
Thanks