Read-Host
Reads a line of input from the console.
语法
Default (默认值)
Read-Host
[[-Prompt] <Object>]
[-AsSecureString]
[<CommonParameters>]
说明
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.
示例
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 key is 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 SecureString object in the $pwd_secure_string variable.
参数
-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).
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | 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.
参数属性
类型: | Object |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | 0 |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
输入
None
You cannot pipe input to this cmdlet.
输出
System.String or System.Security.SecureString
If the AsSecureString parameter is used, Read-Host returns a SecureString. Otherwise, it returns a string.