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
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
Beginning with Carbon 2.0, you can pipe passwords to
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.
The username. Beginning with Carbon 2.0, this parameter is optional. Previously, this parameter was required.
The password. Can be a
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.