< Back
New-CCredential
Post
NAME New-CCredential
SYNOPSIS
Creates a new `PSCredential` object from a given username and password.
SYNTAX
New-CCredential [[-UserName] <String>] [-Password] <Object> [<CommonParameters>]
DESCRIPTION
`New-CCredential` 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-CCredential`, e.g.
Read-EncrptedPassword | Unprotect-CString | New-CCredential -Username 'fubar'
We do *not* recommend passing plaintext passwords around. Beginning ing with Carbon 2.0, you can use
`Unprotect-CString` to decrypt secrets securely to `SecureStrings` and then use those secure strings with
`New-CCredential` to create a credential.
PARAMETERS
-UserName <String>
The username. Beginning with Carbon 2.0, this parameter is optional. Previously, this parameter was required.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Password <Object>
The password. Can be a `[string]` or a `[System.Security.SecureString]`.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Management.Automation.PSCredential.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>New-CCredential -User ENTERPRISE\\picard -Password 'earlgrey'
Creates a new credential object for Captain Picard.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Read-EncryptedPassword | Unprotect-CString | New-CCredential -UserName 'ENTERPRISE\\picard'
Demonstrates how to securely decrypt a secret into a new credential object.
RELATED LINKS
Protect-CString
Unprotect-CString
SYNOPSIS
Creates a new `PSCredential` object from a given username and password.
SYNTAX
New-CCredential [[-UserName] <String>] [-Password] <Object> [<CommonParameters>]
DESCRIPTION
`New-CCredential` 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-CCredential`, e.g.
Read-EncrptedPassword | Unprotect-CString | New-CCredential -Username 'fubar'
We do *not* recommend passing plaintext passwords around. Beginning ing with Carbon 2.0, you can use
`Unprotect-CString` to decrypt secrets securely to `SecureStrings` and then use those secure strings with
`New-CCredential` to create a credential.
PARAMETERS
-UserName <String>
The username. Beginning with Carbon 2.0, this parameter is optional. Previously, this parameter was required.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Password <Object>
The password. Can be a `[string]` or a `[System.Security.SecureString]`.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Management.Automation.PSCredential.
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>New-CCredential -User ENTERPRISE\\picard -Password 'earlgrey'
Creates a new credential object for Captain Picard.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Read-EncryptedPassword | Unprotect-CString | New-CCredential -UserName 'ENTERPRISE\\picard'
Demonstrates how to securely decrypt a secret into a new credential object.
RELATED LINKS
Protect-CString
Unprotect-CString