PowerShell Genie

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.

Command 3 min read PowerShell 7 on Windows

Documentation: Microsoft Learn — read-host

Syntax

1PS> Read-Host [[-Prompt] <String>] [-AsSecureString] [-MaskInput] [<CommonParameters>]

Try it

Windows PowerShell

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.

Interactive simulation · fictional data

Examples

Ask a question and store the answer

1PS> $name = Read-Host -Prompt 'Enter your name'
Show reference output

Illustrative output · values vary by environment

Enter your name: Priya
Priya

Read a password without echoing it

1PS> $secure = Read-Host -Prompt 'Enter password' -AsSecureString
Show reference output

Illustrative output · values vary by environment

Enter password: ********

Build a simple confirmation menu

1PS> $choice = Read-Host -Prompt 'Continue? (Y/N)' if ($choice -eq 'Y') { 'Continuing...' }
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.

Microsoft Learn — read-host

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
Genie guideRead-Host

Read-Host is how a PowerShell script asks a question: prompt for a name, a choice, or a confirmation, and read the answer. With -AsSecureString it reads a password without echoing it. The console below is pre-loaded — run it, then change a value and run it again.