Menu isn't working

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 6 days, 19 hours ago.

  • Author
    Posts
  • #68845
    Profile photo of Chad Nathan Jones
    Chad Nathan Jones
    Participant

    Below is my script for giving some menu options to a user but I always get the Else statement with "No Valid Selection"

    function mainmenu{  
     cls 
     echo "Please Select Office Location"
     echo "---------------------------------------------------------"  
     echo "    1. City"  
     echo "    2. City2"  
     echo "    3. City3"  
     echo "    4. city4"  
     echo "---------------------------------------------------------"    
     $ouAnswer = read-host "Please Make a Selection"  
     if ($ouAnswer -eq 1){$floorou = "ou=Users,ou=City,dc=domain,dc=local"}  
     if ($ouAnswer -eq 2){$floorou = "ou=Users,ou=City2,dc=domain,dc=local"}  
     if ($ouAnswer -eq 3){$floorou = "ou=Users,ou=City3,dc=domain,dc=local"}
     if ($ouAnswer -eq 4){$floorou = "ou=Users,ou=City4,dc=domain,dc=local"}
     else {write-host -ForegroundColor red "Invalid Selection"  
           sleep 5  
           mainmenu  
          }  
                    }  
     mainmenu
    
  • #68847
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You're using the construct incorrectly, unfortunately. The Else is only coupled with the final If, so if that If isn't true, the Else runs.

    You probably want to be using the Switch construct instead.

You must be logged in to reply to this topic.