Use CHOICE to Prompt for Input

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!


Posted Mar 01 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.