A Simple PowerShell Menu

Here’s a quick and dirty interactive menu you can use in PowerShell:

CLS
 do {
Write-Host "Select your option"
Write-Host ""
Write-Host "1 - This is option 1"
Write-Host "2 - This is option 2"
Write-Host "3 - This is option 3"
Write-Host ""
$Option = (Read-Host "Choose from options 1-3")
switch($Option) {
1 {
Write-Host ""
Write-Host "You chose option 1!" -ForegroundColor Green
}
2 {
Write-Host ""
Write-Host "You chose option 2!" -ForegroundColor Yellow
}
3 {
Write-Host ""
Write-Host "You chose option 3!" -ForegroundColor Red
}
Default {
CLS
Write-Host ""
Write-Host "Invalid Option. Enter 1 or 2." -foregroundcolor red
Write-Host ""
}
}
 }
 while ($Option -ne "1" -and $Option -ne "2" -and $Option -ne "3")

This menu presents the user with 3 choices and performs something different depending on which option the user selects. If the user enters 9 or “booger”, the Default option executes, and the do…while loop causes the menu to reload.

Leave a Reply

Your email address will not be published. Required fields are marked *