Hi,
I’m trying to create a menu where the user just select one option and if the option doesn’t exists it asks to type the option again. If the option exists, it runs the code.
The problem is, using the code below when I type “1” it runs ok. When I type “2” it goes into the if statement to show the “try again” message and then it runs the code like it was supposed to…
What I’m doing wrong? I think that is something with the two character options “15”… Maybe?
function Menu{
$Loop = $True
While ($Loop){
Clear-Host
Write-Host
Write-Host "Management console - Office 365 and Exchange Online" -ForegroundColor Green
Write-Host
Write-Host "`t1) Manage distribution groups" -ForegroundColor Yellow
Write-Host "`t2) Manage resources" -ForegroundColor Yellow
Write-Host "`t3) Manage users" -ForegroundColor Yellow
Write-Host "`t4) Verify licenses" -ForegroundColor Yellow
{ ....other options... }
Write-Host "`t15) Quit console" -ForegroundColor Yellow
Write-Host
$Option = Read-Host “Select an option [1-15]”
if (($Option -lt 1) -or ($Option -gt 15)){
Clear-Host
Write-Host
Write-Host “`tThis option doesn’t exist… Try again.” -ForegroundColor Red
Write-Host
Pause
Clear-Host
$Loop = $True
}
Switch ($Option){
1{
DGMenu
}
2{
ResourcesMenu
}
{ ...other options... }
5{
$Loop = $True
Get-PSSession | Where-Object {$_.ConfigurationName -eq "Microsoft.Exchange"} | Remove-PSSession
Clear-Host
Set-Location C:\
Exit
}