Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: How to process multiple ValidationSet parameter attribute values efficiently?

$
0
0

Well, in this specific case, I'd probably just look at the first letter of each parameter, since you know that they can only be Y/Yes or N/No. That would cut down on half of your conditions:

if ($Param1 -like 'Y*' -and $Param2 -like 'Y*' -and $Param3 -like 'Y*')
{
    # do something
}

The fact that you're defining these parameters as arrays throws a wrench in the works, though… then these conditions are really saying "if any of the elements in the array are Y or Yes for all three arrays, do something."

Personally, I would just use switch parameters here, or at the least, booleans. Those already do a good job of indicating "yes/no" style values (true/false):

function Do-Something
{
    [CmdletBinding()]
    Param
    (
        [switch] $Param1,
        [switch] $Param2,
        [switch] $Param3
    )
 
    if ($Param1 -and $Param2 -and $Param3)
    {
        # Do Something
    }
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles