Use CHOICE to Prompt for Input

by Mar 1, 2010

PowerShell can run native console applications, which can be very helpful. For example, you should take a closer look at CHOICE.EXE, which will prompt you for information:

Choice /N /C:123 /M "Enter a number between 1 and 3!"
"Your choice: $LASTEXITCODE"

This will get you a simple Y/N prompt:

Choice /N /C:YN /M "Do you agree (Y/N)?"
"Your answer: $LASTEXITCODE"

Twitter This Tip! ReTweet this Tip!