Skip to content

Fixes #5021 - add MaskInput parameter #6069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions reference/5.1/Microsoft.PowerShell.Utility/Read-Host.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ online version: https://docs.microsoft.com/powershell/module/microsoft.powershel
schema: 2.0.0
title: Read-Host
---

# Read-Host

## SYNOPSIS
Expand All @@ -21,37 +20,39 @@ Read-Host [[-Prompt] <Object>] [-AsSecureString] [<CommonParameters>]
```

## 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.

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.

## EXAMPLES

### Example 1: Save console input to a variable

```
PS C:\> $Age = Read-Host "Please enter your age"
```
This example 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.

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.
```powershell
$Age = Read-Host "Please enter your age"
```

### Example 2: Save console input as a secure string

```
PS C:\> $pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```
This example 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.

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.
```powershell
$pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```

## 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**).
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**).

```yaml
Type: SwitchParameter
Expand All @@ -66,10 +67,11 @@ 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.
PowerShell appends a colon (`:`) to the text that you enter.

```yaml
Type: Object
Expand All @@ -84,24 +86,30 @@ Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. 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.SecureString
If the *AsSecureString* parameter is used, **Read-Host** returns a **SecureString**.
Otherwise, it returns a string.

If the **AsSecureString** parameter is used, `Read-Host` returns a **SecureString**. Otherwise, it
returns a string.

## NOTES

## RELATED LINKS

[Clear-Host](../Microsoft.PowerShell.Core/Clear-Host.md)
[Clear-Host](../microsoft.powershell.core/clear-host.md)

[Get-Host](Get-Host.md)

Expand Down
50 changes: 29 additions & 21 deletions reference/6/Microsoft.PowerShell.Utility/Read-Host.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ online version: https://docs.microsoft.com/powershell/module/microsoft.powershel
schema: 2.0.0
title: Read-Host
---

# Read-Host

## SYNOPSIS
Expand All @@ -21,37 +20,39 @@ Read-Host [[-Prompt] <Object>] [-AsSecureString] [<CommonParameters>]
```

## 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.

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.

## EXAMPLES

### Example 1: Save console input to a variable

```
PS C:\> $Age = Read-Host "Please enter your age"
```
This example 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.

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.
```powershell
$Age = Read-Host "Please enter your age"
```

### Example 2: Save console input as a secure string

```
PS C:\> $pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```
This example 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.

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.
```powershell
$pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```

## 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**).
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**).

```yaml
Type: SwitchParameter
Expand All @@ -66,10 +67,11 @@ Accept wildcard characters: False
```

### -Prompt

Specifies the text of the prompt.
Type a string.
If the string includes spaces, enclose it in quotation marks.
PowerShell appends a colon (:) to the text that you enter.
PowerShell appends a colon (`:`) to the text that you enter.

```yaml
Type: Object
Expand All @@ -84,18 +86,24 @@ Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. 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.SecureString
If the *AsSecureString* parameter is used, **Read-Host** returns a **SecureString**.
Otherwise, it returns a string.

If the **AsSecureString** parameter is used, `Read-Host` returns a **SecureString**. Otherwise, it
returns a string.

## NOTES

Expand Down
50 changes: 29 additions & 21 deletions reference/7.0/Microsoft.PowerShell.Utility/Read-Host.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ online version: https://docs.microsoft.com/powershell/module/microsoft.powershel
schema: 2.0.0
title: Read-Host
---

# Read-Host

## SYNOPSIS
Expand All @@ -21,37 +20,39 @@ Read-Host [[-Prompt] <Object>] [-AsSecureString] [<CommonParameters>]
```

## 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.

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.

## EXAMPLES

### Example 1: Save console input to a variable

```
PS C:\> $Age = Read-Host "Please enter your age"
```
This example 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.

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.
```powershell
$Age = Read-Host "Please enter your age"
```

### Example 2: Save console input as a secure string

```
PS C:\> $pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```
This example 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.

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.
```powershell
$pwd_secure_string = Read-Host "Enter a Password" -AsSecureString
```

## 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**).
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**).

```yaml
Type: SwitchParameter
Expand All @@ -66,10 +67,11 @@ Accept wildcard characters: False
```

### -Prompt

Specifies the text of the prompt.
Type a string.
If the string includes spaces, enclose it in quotation marks.
PowerShell appends a colon (:) to the text that you enter.
PowerShell appends a colon (`:`) to the text that you enter.

```yaml
Type: Object
Expand All @@ -84,18 +86,24 @@ Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. 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.SecureString
If the *AsSecureString* parameter is used, **Read-Host** returns a **SecureString**.
Otherwise, it returns a string.

If the **AsSecureString** parameter is used, `Read-Host` returns a **SecureString**. Otherwise, it
returns a string.

## NOTES

Expand Down
Loading