Author Posts

September 4, 2016 at 2:52 pm

Hey All,

This is probably a simple issue that can be fixed quickly but I need another repair of eyes. Below is my code. I'm trying to keep this menu in a loop until the user is finished. I set a simple if-else statement to ask the user if they are finished and it should end loop and continue. Instead, it's kept in endless loop, I'm sure there is something missing. I'm open to other methods of achieving this but would like if someone can help repair this path.

Do {
Write-host "1. Brokers"
Write-host "2. Capital Advisory"
Write-host "3. Interns"
Write-host "4. Retail Leasing"
Write-host "5. Accounting"
Write-host "6. Analysts- Full"
Write-host "7. Analyst File Access"
write-host "8. Assistants"
write-host "9. ern"
Write-host "10. Quit and exit"
[Int]$xMenuChoiceA = read-host "Please Choose File Access Groups for User 1-10.."
Switch( $xMenuChoiceA ){
1{get-brokers}
2{set-ca}
3{add-intern}
4{add-retaillease}
5{set-accounting}
6{add-analystfull}
7{add-analsystfile}
8{set-assistants}
9{remove-ern}
default{}
}

$continue=read-host "Another Group Needed? Y or N"
if ($continue -eq "Y"){
$continue=$true
}
else{
$continue=$false
}

} while ($continue=$true)

September 4, 2016 at 3:18 pm

The comparison is -eq not =, but since it's a Boolean already just

While ($continue)

Will work.

September 4, 2016 at 3:23 pm

Your while statement is incorrect. You're assigning $true as a value to $continue not testing for $true.

} while ($continue=$true)

Change it to below and it will work.

} while ($continue)

or

} while ($continue -eq $true)

September 5, 2016 at 1:05 pm

Note:

$here = @"

1. Brokers
2. Capital Advisory
3. Interns
4. Retail Leasing
5. Accounting
6. Analysts- Full
7. Analyst File Access
8. Assistants
9. ern
10. Quit and exit

"@

$here