Read-Host
Use Read-Host to pause a script, ask the user a question, and read their answer back as a string — or as a secure string for passwords.
Documentation: Microsoft Learn — read-host
Syntax
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Examples
Ask a question and store the answer
Show reference output
Illustrative output · values vary by environment
Enter your name: Priya Priya
Read a password without echoing it
Show reference output
Illustrative output · values vary by environment
Enter password: ********
Build a simple confirmation menu
Show reference output
Illustrative output · values vary by environment
Continue? (Y/N): Y Continuing...
Parameters
Parameter definitions:
-Prompt— The question shown to the user before reading input.-AsSecureString— Reads the input as a SecureString and shows asterisks instead of the typed characters.-MaskInput— Masks typed input with asterisks but returns a plain string. Available in recent PowerShell 7 releases.
Read-Host returns text, not numbers
Everything Read-Host returns is a string, even when the user types digits. Compare with -eq 'Y', not -eq 1, and cast when you need a number: [int](Read-Host 'Enter a port').
For passwords, prefer -AsSecureString over plain Read-Host. The result is a SecureString you can pass straight to New-Object PSCredential or ConvertTo-SecureString without the password ever existing as plain text.
Avoid Read-Host in scripts that must run unattended. A prompt with nobody to answer it hangs the script forever. Use parameters with defaults for automation, and reserve Read-Host for interactive tools.
Prompt for full credentials with Get-Credential
Write coloured prompts with Write-Host
Updated 25 October 2026. Browser outputs are fictional; check the installed module help for your environment.
Recap
Read-Host Use Read-Host to pause a script, ask the user a question, and read their answer back as a string — or as a secure string for passwords.
Next: Write Host