Best way to ensure combinations from the ValidationSet parameter attribute are processed correctly in PowerShell without using multiple IF statements?

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

Is this what you are trying to ask how to do?  Your posted script is written incorrectly and will not work at all. 
Function Do-Something{
[cmdletbinding()]
Param (
[Parameter(Mandatory=$true)]
[ValidateSet('Yes','No','Y','N')]
[string]$p1,
[Parameter(Mandatory=$true)]
[ValidateSet('Yes','No','Y','N')]
[string]$p2
Begin{
Process{
# parse the strings to booleans
$p1a=if($p1 -match 'Yes|Y'){$true}else{$false}
$p2a=if($p2 -match 'Yes|Y'){$true}else{$false}
if($p1a){Write-Host 'P1 is good' -ForegroundColor green}
if($p2a){Write-Host 'P2 is good' -ForegroundColor green}
if($p1a -and $p2a){
Write-Host 'All conditions met' -ForegroundColor green
}else{
Write-Host 'Conditions not met' -ForegroundColor red
PS C:\scripts> Do-Something Y n
P1 is good
Conditions not met
PS C:\scripts> Do-Something n n
Conditions not met
PS C:\scripts> Do-Something y y
P1 is good
P2 is good
All conditions met
This handles case and creates a tracking Boolean fo reach parameter so you can just build simple logic.
¯\_(ツ)_/¯

Similar Messages

  • I own CS4, upgraded to CS5, then joined CS6, CC... and now I installed CC14. Which will be the best way to delete or uninstall the programs I don't need keeping only CC14 without running into issues? I have an Alienware Area 51 PC running Windows 7.

    I own CS4, upgraded to CS5, then joined CS6, CC... and now I installed CC14. Which will be the best way to delete or uninstall the programs I don't need keeping only CC14 without running into issues? I have an Alienware Area 51 PC running Windows 7.

    Which will be the best way to delete or uninstall the programs I don't need keeping only CC14 without running into issues?
    There is none. Whatever you do to get rid of the older versions will inevitably do damage to shared components and other stuff of the new versions as well. That's just how it is with this approach... Uninstall the older versions, run the cleaner tool then reinstall CC 2014.
    Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6
    Mylenium

  • What is the best way to manage Videos from the iPhone 3GS

    I want manage videos like pictures.
    All vids is stored in my iPhoto Library.
    What is the best way to sync them ?

    iPhoto supports importing photos and videos from a digital camera that supports capturing video as well as photos.
    If the videos were deleted from your iPhone after the iPhoto import process was complete, and you want to transfer a video or videos back to your iPhone for viewing, you need to transfer the videos to iTunes that you want transfered to your iPhone via the iTunes sync process as with any other video.

  • What is the best way to remove footage from the middle of a clip?

    What is the best way to remove unwanted footage from the middle of a clip? I have a clip that I've trimmed from the start and finsih, but I need to remove "boring" footage from inbetween.

    Thank you for your replies. I tried the blade tool followed by select and delete but it did not seem very precise. I had better success with this aproach at the ends rather than in the middle. I watched a tutorial video on using the precision editor, but the video was small so I had a difficult time following where the person clicked, etc. Any info on using the precision editor would be greatly appreciated. I need to make precise cuts to avoid creating unatural motion for the subject. So far, close but no cigar.
    Regards,
    Michael

  • What is the best way to remove files from the hard drive?

    I'm donating one of my computers, and there are certain sensitive files (bank records, etc.) I need to remove. I want them completely removed to the point it's like they never existed, so any hard drive recovery tools can never find them.

    Then you will have to get a replacement set from Apple.
    Since the DVD are your license to OS X they really should be included with the Mac when you sell it.
    Allan

  • What is the best way to trim audio from the front?

    I have a 4 minute video clip and song is 4:40 with a lot of intro so I want to back up the audio to catch about the last 4 minutes.
    Easy answer I am sure but I am a rookie with iMovie.
    Thanks

    You could select the audio clip and fire up the Clip Trimmer (off the Window menu). Then, you can play with the beginning and end AND slide the content left and right to get the point you want at the beginning of the clip.
    Rick

  • I plug my iPod into my computer. The screen lights up, but doesn't pull a charge from the computer, nor does it register in iTunes. Have used multiple cords, tried on two different computers. Does this sound familiar to anyone?

    I have no idea what is going on with my iPod. Am I going to have to go to an Apple store?
    -G

    See if placing the iPod in DFU mode will allow a restore.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    If not then it is time for an appointment at the Genius Bar of an Apple store.

  • How is the best way to remove something from a photo?

    How is the best way to remove something from a photo?

    This is difficult to answer without fully knowing what you are trying to do.
    That said, a few excellent and user friendly retouching tools include:  The Spot Heealing Brush Tool, Healing Brush Tool, Patch Tool, and the Cloning Stamp Tool.

  • How is the best way to read data from an iphone if you lost your itunes data after a crash?

    How is the best way to read data from an iphone if you lost your itunes data after a crash?

    How is the best way to read data from an iphone if you lost your itunes data after a crash?

  • Whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    whats the best way to transfer everything from my old macbook pro to a new mac mini, i have a external hard drive which i backup to regularly via time capsule

    Check out > OS X Lion: How to use Migration Assistant to transfer files from another Mac

  • In Acrobat Professional 8, what is the best way to insert/combine multiple pdf's together in a large

    In Acrobat Professional 8, what is the best way to insert/combine multiple pdf's together in a large volume?
    We have 300 pdf reports and need to insert a 2 page cover page infront of each report. Not sure if Batch processing is best???
    Thanks for any tips.

    Probably each cover page is different too. I would probably just bite the bullet and do each individually. I would create the 2 cover pages in WORD or other word processor and print to cover.pdf. Then open a PDF and Pages>Insert Pages or the cover.pdf to the front of the open PDF and save as to the current PDF. Then repeat 299 times. Each time you would make the appropriate change to the DOC file and print a new cover.pdf file (you might want to turn off open in Acrobat for this processing in the printer properties to save time). Probably a good idea to keep a list of the files to check off what has been done (you can generate a list in DOS by Start>cmd, change the directory to your location [cd path], and do "dir >>list.txt". That will give you a list to use.). There may be an easier way, but by the time you get it figured out you might be done this way.

  • What could be the best way to Export data from 11.5.8 instance to 12.1.2?

    Hi All
    What could be the best way to Export data from 11.5.8 instance to 12.1.2?
    Release: 11.5.8
    OS: Oracle Solaris on SPARC (32-bit) verison 9
    DB: 9.2.0.1
    Thanks in advance

    What kind of data you are looking to move?
    Database export/import is only supported for full database export/import and the application release should be the same on the source/target nodes.
    You can move the setup using iSetup or FNDLOAD.
    Thanks,
    Hussein

  • What is the best way to import pictures from Lightroom 5 into FCP X

    What is the  best way to transfer pictures from Lightroom 5 into Final Cut Pro X?

    There is no one best way.  If, for instance, you want to be able to zoom into the picture with a Ken Burns effect then you may want to save out a very high res version that will be larger than your video resolution. Just use Lightroom to export a jpg file wherever you want it. You could export it into the Events folder and then choose not to copy it when you import it within FCPx. You could import the picture into iPhoto and then access it directly from within FCPx. Those are two simple, "regular" ways to get it into FCPx but if you are not going to Ken Burns the image by zooming into it and such you will want to crop it in Lightroom to the same size you will be using ie if you are making 720HD video then crop the image to that size and proportion before you export it from Lightroom.

  • What is the best way to import photos from aperture to my new Lightroom

    What is the best way to import photos from aperture to my new Lightroom ?

    See if this helps
    http://lightroomsolutions.com/articles/migrating-from-aperture-to-lightroom-where-do-i-beg in/

  • The best way to import photos from Picasa to iPhoto

    Hi,
    Many of my friends share their pictures online using picasa. Sometimes, I'd like to copy these pictures to keep a backup offline. As a software, I use iPhoto; not picasa. What is the best way to import pictures from picasa to iPhoto?
    I first tried to subscribe to the RSS feed using iPhoto and then copy the pictures from there to my library, but then the dates of the pictures are set wrong: instead of indicating when the picture was shot, it indicates some other date (I guess it indicates the date when the picture was uploaded to picasa).
    Then I decided to install the software picasa.app. From the webalbum of my friends, I could download the pictures directly to picasa.app. Then I exported them to the desktop, and from there imported them to iPhoto. The dates where set correctly, but I lost all the titles and comments of the pictures.
    Do you have any method to download the pictures while keeping both the dates and the titles correctly?
    Thanx!

    There is a direct option in Organizer which lets you import from iPhoto. This is under Import dropdown menu in left panel.
    If you are importing from iPhoto'09, your Tags, Albums Events, captions, star rating would also get imported apart from your media. This works differently for iPhoto'011 where you can get only the media to the Organizer,
    Just a couple of things to know:
    1. If in iPhoto preferences, you have chosen to create copies of your photos in iPhoto library and your library hence refers to the media store inside the library package, then on importing from iPhoto, Organizer would create copies of all those media under your pictures folder. That means, it would not corrupt your iPhoto package or modify it in any way.
    2. However, if in iPhoto, you are organizing by using references to original location on your Hard drive i.e. you are not creating copies of media in iPhoto library then on importing from iPhoto to Organizer, the Organizer would also use the same references and would not create copies of the media.
    Hope that helps!
    ~V

Maybe you are looking for

  • Slow syncing on my iPhone 3GS

    Hi guys I recently got a 3GS, and i'm trying to transfer music to it on iTunes on Windows 7. However, it's so slow! In 1 hour it manages around 100 tracks, and it keeps freezing for shot periods of time. I've tried doing it manually, and i've tried s

  • My i pod will not play videos they just freeze but they work on itunes

    my i pod will not play any videos that i put on but they work fine on i tunes, they play but 1 second in to the video it just frezzes and you can hear anything so what is wrong.

  • Queries regarding reorganisation of PIRs

    Hi PP Gurus, I have some queries related to re-organization of PIRs using MD76. 1.In order to execute MD76,we first need to execute MD74 and MD75.Execution of MD74 has two parts. a)  Adjustment (reduction) of all planned independent requirements sche

  • How do you convert Raw files into jpeg.

      I have never shot in Raw before and I have a huge project due tomorrow. I need help Asap. What is the easiest way to convert Raw files into jpeg, can Light Room convert the files. I have tried so many different ways and nothing seems to work.

  • Background colour on XP

    We use generic look and feel with use 3D objects = y. In windows XP, Mr. Gates has kindly changed the default colur setting for 3D objects from grey to white. Does anyone know whether it is possible to change this via webutil ? I assume it is a regis