Photo by Lisa Walton on Unsplash

Using the Read-Host PowerShell cmdlet, you can interactively prompt for input from the script user. Let’s see some real-world applications on how we can use the Read-Host PowerShell cmdlet.

Prompting for Input with Read-Host

The Read-Host cmdlet performs two functions in a PowerShell script; it pauses execution and receives input. That’s it. Read-Host is a simple cmdlet but one that comes in useful when needing to get information from the script user.

At it’s most basic, the Read-Host cmdlet simply requires using the Prompt parameter. This Prompt parameter allows you to give the script user some kind of indication as to what to input. For example, if your script requires a server name, you might choose to use Read-Host to prompt the user to input that when the script is run.

You can see below that by executing Read-Host within the PowerShell console itself using the Prompt parameter, PowerShell is stopping all execution and displays my prompt message giving the user an explanatory message as to what we’re after.


Ready to stop reading and start learning about PowerShell, DSC, Windows Server, Sharepoint, IIS and dozens of other categories? If so, check out the hundreds of free technical demo screencasts available on the new, IT career development platform TechSnips.

Read-Host plain text

Let’s incorporate this into a script. Whenever a user inputs information at the prompt, Read-Host returns that information back to your code. You can easily capture this information by assigning the output to a variable. Perhaps I’d like to ask for a server name and then do something with that server name. Otherwise, I’d like to send a warning to the user letting them know that I really, really need that server name.


Using a simple if/then construct, I can then be sure my user inputs a server name. Once they do, I can then capture it and do something with it otherwise, send a warning message.

Read-Host in scripts

Asking for Passwords

You should know it’s not a good idea to store passwords in plain text in your scripts. Likewise, it’s never a good idea to have passwords stored in plain text in memory either. To get around this, PowerShell has a concept called a secure string which is a simple string that’s encrypted.

A secure string can any kind of sensitive information; a password is a great example. What does this have to do with Read-Host? The Read-Host cmdlet has an AsSecureString parameter which allows the user to not only store the output as a secure string but also to show asterisk while typing to hide your secret from prying eyes!

Let’s say I have a deep, dark secret I don’t want anyone to know about but I need to pass this password to some kind of software. You can see below that when I don’t use AsSecureString, you’re onto me! However, if I use AsSecureString, my secret is safe since every character I type is replaced with an asterisk and the output it saved as a secure string rather than a plain-text string.

Read-Host prompting for a password

To reference the Read-Host documentation, check out the Microsoft Docs.

%d bloggers like this: