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

2 years, 1 month ago.

  • Author
  • #68845

    Topics: 11
    Replies: 6
    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{  
     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

    Topics: 13
    Replies: 4872
    Points: 1,811
    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort