I’m looking to create a command line menu in powershell, with the options coming from an array of unknown size.
I had previously been using a switch statement, but at that time I knew how many options there were going to be. Now, the options are being parsed from an XML file, and changing all of the time, so the old way won’t work.
This is the old way:
switch ($a)
{
1 {
Write-Host $USR_ID "on SERVER "$SERVER_NAME"`n"
$query = $USR_ID
}
2 {
Write-Host $PRFL_NM "on SERVER "$SERVER_NAME"`n"
$query = $PRFL_NM
}
3 {
Write-Host $APP_NM "on SERVER "$SERVER_NAME"`n"
$query = $APP_NM
}
4{
Write-Host $COMBO "on SERVER " $SERVER_NAME"`n"
$query = $COMBO
confirm
}
default {
"** Invalid Input **";
exit
}
}
Anybody got any ideas?
Thanks!
Create an array holding objects containing the respective information you need and index into the array instead of using the
switch.I have no idea how your XML looks like and what your various variables are, so it’s hard to give a more precise answer.