Skip to content

Commit 057aab0

Browse files
authored
Updated to avoid clear text password in logs (#11114)
Co-authored-by: Mike F. Robbins <[email protected]>
1 parent d53bb6c commit 057aab0

File tree

4 files changed

+40
-44
lines changed

4 files changed

+40
-44
lines changed

reference/5.1/Microsoft.PowerShell.Security/Get-Credential.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Security.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Security
5-
ms.date: 12/12/2022
5+
ms.date: 05/15/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-credential?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Get-Credential
@@ -109,25 +109,24 @@ might not work in all host programs.
109109

110110
### Example 5
111111

112-
This example shows how to create a credential object that is identical to the object that
113-
`Get-Credential` returns without prompting the user. This method requires a plain text password,
114-
which might violate the security standards in some enterprises.
112+
This example demonstrates how to create a credential object identical to the one returned by
113+
`Get-Credential`.
115114

116115
```powershell
117116
$User = "Domain01\User01"
118-
$PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force
117+
$PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString
119118
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
120119
```
121120

122-
The first command saves the user account name in the `$User` parameter. The value must have the
123-
"Domain\User" or "ComputerName\User" format.
121+
The first command assigns the username to the `$User` variable. Ensure the value follows
122+
the "Domain\User" or "ComputerName\User" format.
124123

125-
The second command uses the `ConvertTo-SecureString` cmdlet to create a secure string from a plain
126-
text password. The command uses the **AsPlainText** parameter to indicate that the string is plain
127-
text and the **Force** parameter to confirm that you understand the risks of using plain text.
124+
The second command uses the `Read-Host` cmdlet to create a secure string from user input. The
125+
**Prompt** parameter requests user input, and the **AsSecureString** parameter masks the input and
126+
converts it to a secure string.
128127

129128
The third command uses the `New-Object` cmdlet to create a **PSCredential** object from the values
130-
in the `$User` and `$PWord` variables.
129+
stored in the `$User` and `$PWord` variables.
131130

132131
### Example 6
133132

reference/7.2/Microsoft.PowerShell.Security/Get-Credential.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Security.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Security
5-
ms.date: 02/26/2024
5+
ms.date: 05/15/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-credential?view=powershell-7.2&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Get-Credential
@@ -89,25 +89,24 @@ documentation in the SDK.
8989

9090
### Example 4
9191

92-
This example shows how to create a credential object that is identical to the object that
93-
`Get-Credential` returns without prompting the user. This method requires a plain text password,
94-
which might violate the security standards in some enterprises.
92+
This example demonstrates how to create a credential object identical to the one returned by
93+
`Get-Credential`.
9594

9695
```powershell
9796
$User = "Domain01\User01"
98-
$PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force
97+
$PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString
9998
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
10099
```
101100

102-
The first command saves the user account name in the `$User` parameter. The value must have the
103-
"Domain\User" or "ComputerName\User" format.
101+
The first command assigns the username to the `$User` variable. Ensure the value follows
102+
the "Domain\User" or "ComputerName\User" format.
104103

105-
The second command uses the `ConvertTo-SecureString` cmdlet to create a secure string from a plain
106-
text password. The command uses the **AsPlainText** parameter to indicate that the string is plain
107-
text and the **Force** parameter to confirm that you understand the risks of using plain text.
104+
The second command uses the `Read-Host` cmdlet to create a secure string from user input. The
105+
**Prompt** parameter requests user input, and the **AsSecureString** parameter masks the input and
106+
converts it to a secure string.
108107

109108
The third command uses the `New-Object` cmdlet to create a **PSCredential** object from the values
110-
in the `$User` and `$PWord` variables.
109+
stored in the `$User` and `$PWord` variables.
111110

112111
### Example 5
113112

reference/7.4/Microsoft.PowerShell.Security/Get-Credential.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Security.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Security
5-
ms.date: 02/26/2024
5+
ms.date: 05/15/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-credential?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Get-Credential
@@ -89,25 +89,24 @@ documentation in the SDK.
8989

9090
### Example 4
9191

92-
This example shows how to create a credential object that is identical to the object that
93-
`Get-Credential` returns without prompting the user. This method requires a plain text password,
94-
which might violate the security standards in some enterprises.
92+
This example demonstrates how to create a credential object identical to the one returned by
93+
`Get-Credential`.
9594

9695
```powershell
9796
$User = "Domain01\User01"
98-
$PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force
97+
$PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString
9998
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
10099
```
101100

102-
The first command saves the user account name in the `$User` parameter. The value must have the
103-
"Domain\User" or "ComputerName\User" format.
101+
The first command assigns the username to the `$User` variable. Ensure the value follows
102+
the "Domain\User" or "ComputerName\User" format.
104103

105-
The second command uses the `ConvertTo-SecureString` cmdlet to create a secure string from a plain
106-
text password. The command uses the **AsPlainText** parameter to indicate that the string is plain
107-
text and the **Force** parameter to confirm that you understand the risks of using plain text.
104+
The second command uses the `Read-Host` cmdlet to create a secure string from user input. The
105+
**Prompt** parameter requests user input, and the **AsSecureString** parameter masks the input and
106+
converts it to a secure string.
108107

109108
The third command uses the `New-Object` cmdlet to create a **PSCredential** object from the values
110-
in the `$User` and `$PWord` variables.
109+
stored in the `$User` and `$PWord` variables.
111110

112111
### Example 5
113112

reference/7.5/Microsoft.PowerShell.Security/Get-Credential.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Security.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Security
5-
ms.date: 02/26/2024
5+
ms.date: 05/15/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.security/get-credential?view=powershell-7.5&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Get-Credential
@@ -89,25 +89,24 @@ documentation in the SDK.
8989

9090
### Example 4
9191

92-
This example shows how to create a credential object that is identical to the object that
93-
`Get-Credential` returns without prompting the user. This method requires a plain text password,
94-
which might violate the security standards in some enterprises.
92+
This example demonstrates how to create a credential object identical to the one returned by
93+
`Get-Credential`.
9594

9695
```powershell
9796
$User = "Domain01\User01"
98-
$PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force
97+
$PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString
9998
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
10099
```
101100

102-
The first command saves the user account name in the `$User` parameter. The value must have the
103-
"Domain\User" or "ComputerName\User" format.
101+
The first command assigns the username to the `$User` variable. Ensure the value follows
102+
the "Domain\User" or "ComputerName\User" format.
104103

105-
The second command uses the `ConvertTo-SecureString` cmdlet to create a secure string from a plain
106-
text password. The command uses the **AsPlainText** parameter to indicate that the string is plain
107-
text and the **Force** parameter to confirm that you understand the risks of using plain text.
104+
The second command uses the `Read-Host` cmdlet to create a secure string from user input. The
105+
**Prompt** parameter requests user input, and the **AsSecureString** parameter masks the input and
106+
converts it to a secure string.
108107

109108
The third command uses the `New-Object` cmdlet to create a **PSCredential** object from the values
110-
in the `$User` and `$PWord` variables.
109+
stored in the `$User` and `$PWord` variables.
111110

112111
### Example 5
113112

0 commit comments

Comments
 (0)