Menu isn't working

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 year, 2 months ago.

  • Author
  • #68845

    Chad Nathan Jones

    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{  
     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  
  • #68847

    Don Jones

    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.