Having trouble getting my menus to work. I would like to make a menu class, but I'm stuck with v2. Each time I enter "1" at the "Main Menu", it will simply re-present me with the main menu instead of re-entering the function with the new $menuType.
function presentMenu{
param ([string]$menuType)
if($menuType = "Main"){
Write-Host "MAIN MENU: 1.) Add Scanner 2.) Remove Scanner 3.) Lookup Scanner Config 4.) Exit"
$command = Read-Host
##DEBUG## write-host $menuType
if ($command -eq 1){
presentMenu("addScaner")
}
elseif ($command -eq 2){
}
elseif ($command -eq 3){
}
elseif ($command -eq 4){
exit
}
elseif ($command -eq 5){
exit
}
else{
presentMenu("Main")
}
}
elseif($menuType = "addScanner"){
Write-Host "ADD SCANNER: 1.) From File 2.) From Input 3.) Back 4.) Exit"
$command = Read-Host
if ($command -eq 1){
addScannerController("File")
}
if ($command -eq 2){
addScannerController("Input")
}
if ($command -eq 3){
presentMenu("Main")
}
if ($command -eq 4){
exit
}
else{
presentMenu("addScanner")
}
}
}
try{
presentMenu("Main")
}
catch{
Write-Error $_.Exception.ToString()
Read-Host -Prompt "The above error occurred. Press Enter to exit."
}
The expected outcome when you enter "1" at the main menu, would be that you are presented with the "addScanner" menu. This really seems like a scope issue to me, but I can't seem to figure out how to correct it?
switchstatement rather thanif..elseif..elseif..=is assignment, but not comparison. BTW, PowerShell is not functional language and, AFAIK, does not support tailcall optimization.