For a simple interactive PowerShell menu, display the choices, collect a response with Read-Host, and use switch to run the matching action. Put the menu in a loop to show it again after each action, handle unexpected input with default, and give users a clear option to quit.
Build a basic repeating menu
This example offers two actions and a quit option. It trims accidental spaces from the response, returns to the menu after an action, and gives an error message for anything it does not recognize.
do {
Clear-Host
Write-Host "Choose an option:"
Write-Host "1. Show date"
Write-Host "2. List files"
Write-Host "Q. Quit"
$choice = (Read-Host "Enter your choice").Trim()
switch ($choice) {
'1' {
Get-Date
Read-Host "Press Enter to return to the menu" | Out-Null
}
'2' {
Get-ChildItem
Read-Host "Press Enter to return to the menu" | Out-Null
}
'Q' {
Write-Host "Goodbye."
}
default {
Write-Host "Choose 1, 2, or Q."
Read-Host "Press Enter to try again" | Out-Null
}
}
} until ($choice -eq 'Q')
The menu arrangement is a coding pattern built from PowerShell’s input, branching, and looping features; there is no built-in menu command in this example. Microsoft documents Read-Host as reading a line of input from the console, while switch maps matching values to action blocks.
How input and choice matching work
Read-Host returns text
By default, Read-Host returns a string, so the sample compares the response with quoted values such as '1'. Convert the response to a number only when you need numeric operations or numeric validation; a menu selection usually needs only a match against known options. The PowerShell 7.5 documentation specifies a maximum input length of 1022 characters.
Recommended Free Tools
#1 Best Overall
- Book - powershell for sysadmins: workflow automation made easy
- Language: english
- Binding: paperback
switch handles recognized and unrecognized entries
Each matching switch clause runs its action block. The default clause handles a response that matches none of the listed choices. Without options such as -Regex or -Wildcard, PowerShell’s switch uses exact, case-insensitive matching; consequently, Q and q both select the quit action here.
The loop controls whether the menu returns
The do block runs the menu and its selected action, then the until condition checks whether the user selected Q. After any other choice—including invalid input—the loop repeats. The pause after an action or error lets the user read the output before the next screen is cleared.
Adapt the menu safely
- Change the displayed choices, matching labels, and validation message together so that users can see exactly which entries are accepted.
- Keep short actions in the menu; move longer work into named functions and call those functions from the relevant
switchblock. - Validate a choice before running work that depends on it. Microsoft’s PowerShell 101 functions guidance advises not letting code continue along a path when it cannot complete without valid input.
- For a function that receives a choice as a parameter, validation attributes can reject invalid submitted values; Microsoft documents that the function is not called when such a value is invalid. This parameter validation is separate from checking a response collected with
Read-Host. See Advanced function parameters for Windows PowerShell 5.1.
Choose an input method that fits the script
A Read-Host menu is for a person interacting with a console. Since it waits for keyboard input, it is unsuitable for unattended jobs unless the script is redesigned to receive a parameter or another noninteractive input source. Microsoft’s training module on accepting input in Windows PowerShell scripts covers distinct options including Read-Host, Get-Credential, Out-GridView, and script parameters; choose based on whether the task needs a console prompt, graphical selection, or invocation-time input. It does not establish a direct feature-by-feature comparison among those methods.
Quick Recap
Best Value
Rank #4
Rank #3
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




