NAME
Read-Host
SYNOPSIS
Reads a line of input from the console.SYNTAX
Read-Host [[-Prompt]
DESCRIPTION
The Read-Host cmdlet reads a line of input from the console. You can use it to prompt a user for input. Because
you can save the input as a secure string, you can use this cmdlet to prompt users for secure data, such as passwords, as well as shared data.PARAMETERS
-AsSecureString [
] Indicates that the cmdlet displays asterisks (*) in place of the characters that the user types as input.
When you use this parameter, the output of the Read-Host cmdlet is a SecureString object (
System.Security.SecureString ). Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false-Prompt
Specifies the text of the prompt. Type a string. If the string includes spaces, enclose it in quotation marks. Windows PowerShell appends a colon (:) to the text that you enter. Required? false Position? 0 Default value None Accept pipeline input? False Accept wildcard characters? falseThis cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS
None You cannot pipe input to this cmdlet.OUTPUTS
System.String or System.Security.SecureStringIf the AsSecureString parameter is used, Read-Host returns a SecureString . Otherwise, it returns a string.
NOTES
Example 1: Save console input to a variable
PS C:\>$Age = Read-Host "Please enter your age"
This command displays the string "Please enter your age:" as a prompt. When a value is entered and the Enter keyis pressed, the value is stored in the $Age variable.
Example 2: Save console input as a secure string
PS C:\>$pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
This command displays the string "Enter a Password:" as a prompt. As a value is being entered, asterisks (*)
appear on the console in place of the input. When the Enter key is pressed, the value is stored as a SecureStringobject in the $pwd_secure_string variable.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821843Clear-Host
Get-Host
Write-Host