PowerTip: Prompt for Input for PowerShell Script

Doctor Scripto

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.


Discussion is closed.

Feedback usabilla icon