October 24th, 2015

PowerTip: Prompt for Input for PowerShell Script

Doctor Scripto
Scripter

Summary: Learn how to prompt for input for your Windows PowerShell script.

Hey, Scripting Guy! Question How can I use Windows PowerShell as an easy way to prompt a user for information for my script?

Hey, Scripting Guy! Answer Use Read-Host, for example:

$a = Read-Host -Prompt "enter your input"

The users input is stored in the $a variable.

Note  Depending on what you are doing, using unchecked user input for your script can be dangerous.
It is best to limit user input to prespecified actions. The second best thing is to check the user input to
ensure that it meets certain requirements.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.