Read-Host

 

Additional Resources for Read-Host

 

Prompting a User to Enter Information

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/read-host.mspx

 

 

SYNOPSIS

Reads a line of input from the console.

 

SYNTAX

Read-Host [[-prompt] <Object>] [-asSecureString] [<CommonParameters>]

 

DETAILED DESCRIPTION

Reads a line of input from the console. Can be used to prompt for input from a user. Can also be used to create secure strings.

 

PARAMETERS

 

-prompt <Object>

This is the string that will become the prompt object. If the prompt string includes spaces, it must be surrounded by quotes.

 

Required?

false

Position?

1

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-asSecureString <SwitchParameter>

If set to true, the input will be echoed as star characters (*). The output will then be a Securestring object.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

RETURN TYPE

String or SecureString

 

NOTES

 

For more information, type "Get-Help Read-Host  -detailed". For technical information, type "Get-Help Read-Host -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

$age = read-host "Please enter your age:"

 

This command presents the string "Please enter your age:" as a prompt. When a value is entered and the Enter key is pressed, that value is stored in the $age variable.

 

EXAMPLE 2

 

$a = read-host "Enter the machine name here"

 

EXAMPLE 3

 

$pwd_secure_string = read-host "Enter a Password:" -assecurestring

 

This command presents the string "Enter a Password:" as a prompt. As a value is being entered, each key press results in the display of an asterisk (*). When the Enter key is pressed, the value is stored as a SecureString in the $pwd_secure_string variable.

 

RELATED LINKS

Get-Host

Out-Host

Write-Host

ConvertFrom-SecureString