Menu isn't working

Welcome Forums General PowerShell Q&A Menu isn't working

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 8 months ago.

  • Author
    Posts
  • #68845

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Menu isn't working’ is closed to new replies.