Search notes:

PowerShell cmdLet: Read-Host

read-host reads a line of input.
Usually, read-host is used to assign a text that is entered by a user to a variable:
$val = read-host
write-output $val

Adding a prompt

With -prompt, the user is shown a text after which the value can be entered:
$val = read-host -prompt 'Please enter a value'
Because -prompt is the first parameter of read-host, the string -prompt can also be left out.

Entering secure strings

With -asSecureString, the entered value is masked with asterisks and read-host returns a System.Security.SecureString:
PS C:\> $sec = read-host -prompt 'Password' -asSecureString
Password: ******
PS C:\> $sec
System.Security.SecureString
PS C:\> convertFrom-secureString $sec
01000000d08c9ddf0115d1118…

See also

Powershell command noun: host

Index