Selectable variables

Hey everyone,

Im working on a script again and i need some help again. in the current script uses alot of variables. but what i want is that when i start the script i want to have a choice for example “1 or 2” and when i select “1” the script continues using the variables and ignores the variables assigned under “2” assigned to choice 1. and off course when selecting “2” it continues using variables assigned to “2”

offcourse i can duplicate the .ps1 file and change the variables, but i really want to know of this is possible, below an example of what i want

$Route = Read-host “choose route 1 of 2”
if ( $Route = 1 ) {
write-host “Route 1 chosen” -foregroundcolor green
} else
write-host “Route 2 chosen” -ForegroundColor Red


thx in advance

Of course that’s possible.

There are several options available.

You could use a switch parameter and run the script with a default set if you run it without this switch parameter and switch to the non default set when the switch parameter is provided.

Or you could use a mandatory parameter with a validate set or a validate range. If you run the script without any parameters provided it will ask for the mandatory parameter and will only accept values from the given validate set or validate range.

Or you could use parameter sets with mutual exceptions.

You should start to read the help topic about_Functions_Advanced

and continue reading

… or …

And BTW: Could you please format your code as code unsing the preformatted text button ( </> )?
Thanks in advance.

Thx for your reply, in the script i was working on already had a few switch options. wonder why i couldnt think of using the switch option again voor this question. :thinking:

Sometimes you cannot see the forest for the trees and a fresh (another) pair of eyes can see something what you haven’t seen by yourself.