To prompt for input in PowerShell, use Read-Host. It shows your message, waits until the user types something and presses Enter, and returns what they typed:
$name = Read-Host -Prompt 'Enter your first name'
"Hello, $name! Your report is ready."
Output (what I typed follows the colon):
Enter your first name: Maria
Hello, Maria! Your report is ready.
PowerShell adds the colon and space after your prompt text, so leave them out of the message. The value goes into $name, and you can use it like any other variable.
For this guide I ran every script in real PowerShell 7.6 and Windows PowerShell 5.1 consoles and typed the answers in. The outputs show exactly what appeared on screen.
Read-Host always returns text
Even when the user types a number, Read-Host gives you a string. That leads to surprising math:
$licenses = Read-Host -Prompt 'How many licenses'
"Read-Host returned a $($licenses.GetType().Name)"
"Doubled as text: $($licenses * 2)"
"Doubled as a number: $([int]$licenses * 2)"
Output:
How many licenses: 5
Read-Host returned a String
Doubled as text: 55
Doubled as a number: 10
Multiplying the text '5' by 2 repeats it, so you get 55. Convert the answer with [int] before you calculate. See how to convert a string to an integer for other number types.
Validate the input and ask again
Users make typos, so check the answer and prompt again until it’s valid. -as [int] returns nothing instead of an error when the text isn’t a number:
do {
$answer = Read-Host -Prompt 'Number of licenses (1-100)'
$licenses = $answer -as [int]
} until ($licenses -ge 1 -and $licenses -le 100)
"Ordering $licenses licenses."
Output:
Number of licenses (1-100): ten
Number of licenses (1-100): 250
Number of licenses (1-100): 25
Ordering 25 licenses.

The loop only exits when the answer is a whole number from 1 to 100. “ten” failed the conversion, and 250 was out of range.
How do I give Read-Host a default value?
Read-Host has no default parameter. Show the default in the prompt, then use it when the answer is empty. Here I just pressed Enter:
$city = Read-Host -Prompt 'Office city [Austin]'
if ([string]::IsNullOrWhiteSpace($city)) {
$city = 'Austin'
}
"Using office: $city"
Output:
Office city [Austin]:
Using office: Austin
IsNullOrWhiteSpace() also catches an answer that’s only spaces, which a plain -eq '' check would miss.
Why ?? doesn’t work here
In PowerShell 7, you might reach for the null-coalescing operator. It doesn’t help, because pressing Enter returns an empty string, not $null:
$city = (Read-Host -Prompt 'Office city [Austin]') ?? 'Austin'
"Using office: [$city]"
Output in PowerShell 7:
Office city [Austin]:
Using office: []
The brackets show that $city is empty. ?? only replaces $null, so stick with the IsNullOrWhiteSpace() check.
Ask a yes or no question
Loop until the answer is one you expect. -in and -eq ignore case, so Y and y both work:
do {
$reply = Read-Host -Prompt 'Delete 42 old log files? (y/n)'
} until ($reply -in 'y', 'n')
if ($reply -eq 'y') { 'Deleting files...' } else { 'Cancelled. Nothing was deleted.' }
Output:
Delete 42 old log files? (y/n): maybe
Delete 42 old log files? (y/n): n
Cancelled. Nothing was deleted.
For anything destructive, make “no” the safe path, as it is here. The script only deletes when the answer is exactly y.
Read multiple lines of input
Read-Host reads one line at a time, so call it in a loop and stop at an empty line:
$servers = [System.Collections.Generic.List[string]]::new()
while ($true) {
$name = Read-Host -Prompt 'Server name (press Enter when done)'
if ([string]::IsNullOrWhiteSpace($name)) { break }
$servers.Add($name)
}
"You entered $($servers.Count) servers: $($servers -join ', ')"
Output:
Server name (press Enter when done): WEB01
Server name (press Enter when done): WEB02
Server name (press Enter when done): SQL01
Server name (press Enter when done):
You entered 3 servers: WEB01, WEB02, SQL01

I used a generic List instead of += on an array, which gets slow when the list grows. Each answer can be up to 1,022 characters, which is Read-Host’s limit.
Prompt for a password
Add -AsSecureString and PowerShell shows an asterisk for each character. You get a SecureString back instead of plain text:
$password = Read-Host -Prompt 'Password for svc-backup' -AsSecureString
"Stored as a $($password.GetType().Name) with $($password.Length) characters"
Output:
Password for svc-backup: ************
Stored as a SecureString with 12 characters

Most cmdlets that need a password, like New-LocalUser, accept a SecureString directly. To sign in with it, build a credential. See how to create a credential object in PowerShell.
Masked input as plain text (PowerShell 7)
PowerShell 7.1 added -MaskInput. The typing is hidden the same way, but you get a normal string:
$pin = Read-Host -Prompt 'Four-digit PIN' -MaskInput
"Got a $($pin.GetType().Name) with $($pin.Length) characters"
Output in PowerShell 7:
Four-digit PIN: ****
Got a String with 4 characters
Windows PowerShell 5.1 doesn’t have -MaskInput. There, and in scripts that must run in both versions, use -AsSecureString and convert only when you have to:
$secure = Read-Host -Prompt 'API key' -AsSecureString
$plain = [System.Net.NetworkCredential]::new('', $secure).Password
"The key starts with $($plain.Substring(0, 4))"
Output:
API key: **********
The key starts with demo
Keep plain-text secrets in memory for as short a time as possible, and never write them to a log or the console.
Use a mandatory parameter instead
For scripts other people run, a parameter is often better than Read-Host. Mark it Mandatory and PowerShell prompts for it when it’s missing:
param(
[Parameter(Mandatory)]
[string]$ComputerName
)
"Checking disk space on $ComputerName..."
Output:
cmdlet mandatory.ps1 at command pipeline position 1
Supply values for the following parameters:
ComputerName: WEB01
Checking disk space on WEB01...
The difference is that the same script also runs unattended, as .\mandatory.ps1 -ComputerName WEB01, with no prompt at all. More in how to run a PowerShell script with parameters.
Read-Host in scheduled tasks
Read-Host needs someone at the keyboard. In a scheduled task, a CI pipeline, or any session started with -NonInteractive, it fails:
$name = Read-Host -Prompt 'Enter your first name'
Output in PowerShell 7:
Read-Host: C:\psfaqs\noninteractive.ps1:1
Line |
1 | $name = Read-Host -Prompt 'Enter your first name'
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
Windows PowerShell 5.1 shows the same message in its own error format. If a script might run unattended, take the value as a parameter and only fall back to Read-Host for interactive use.
Microsoft lists every option in the Read-Host documentation.
Frequently Asked Questions
How do I prompt for user input in PowerShell?
Use $answer = Read-Host -Prompt 'Your question'. PowerShell shows the prompt, waits for Enter and stores the typed text in $answer.
How do I set a default value for Read-Host?
Check the answer and fall back to the default: if ([string]::IsNullOrWhiteSpace($answer)) { $answer = 'Austin' }. The ?? operator doesn’t work, because an empty answer isn’t $null.
How do I hide a password typed into Read-Host?
Add -AsSecureString. Each character shows as an asterisk and you get a SecureString. In PowerShell 7.1 and later, -MaskInput masks the input but returns plain text.
Why does Read-Host treat my number as text?
Read-Host always returns a string. Convert it with [int]$answer, or use $answer -as [int] to get nothing instead of an error for bad input.
Why does Read-Host fail in a scheduled task?
Scheduled tasks run without a console user, often with -NonInteractive, so Read-Host can’t prompt. Pass the value as a script parameter instead.
If you’re building interactive scripts, these help too:
- While loops in PowerShell
- PowerShell switch parameters
- Pass arrays as parameters
- Create a credential object
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.