Creates a new PSCredential object from a given username and password.
New-Credential [[-UserName] <String>] [-Password] <Object> [<CommonParameters>]
New-Credential will create a credential for you from a username and password, converting a password stored as a String into a SecureString.
PowerShell commands use PSCredential objects instead of username/password. Although Microsoft recommends using Get-Credential to get credentials, when automating installs, there's usually no one around to answer that prompt, so secrets are often pulled from encrypted stores.
Beginning with Carbon 2.0, you can pass a SecureString as the value for the Password parameter.
Beginning with Carbon 2.0, you can pipe passwords to New-Credential, e.g.
Read-EncrptedPassword | Unprotect-String | New-Credential -Username 'fubar'
We do not recommend passing plaintext passwords around. Beginning ing with Carbon 2.0, you can use Unprotect-String to decrypt secrets securely to SecureStrings and then use those secure strings with New-Credential to create a credential.
| Name | Type | Description | Required? | Pipeline Input | Default Value |
|---|---|---|---|---|---|
| UserName | String | The username. Beginning with Carbon 2.0, this parameter is optional. Previously, this parameter was required. |
false | false | |
| Password | Object | The password. Can be a |
true | true (ByValue) |
New-Credential -User ENTERPRISE\picard -Password 'earlgrey'
Creates a new credential object for Captain Picard.
Read-EncryptedPassword | Unprotect-String | New-Credential -UserName 'ENTERPRISE\picard'
Demonstrates how to securely decrypt a secret into a new credential object.