commands

^

New-DbaCredential

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out New-DbaCredential on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaCredential.

Synopsis

Creates a new SQL Server credential

Description

Creates a new credential

Syntax

New-DbaCredential
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Name] <String>]
    [-Identity] <String>
    [[-SecurePassword] <SecureString>]
    [[-MappedClassType] <String>]
    [[-ProviderName] <String>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> New-DbaCredential -SqlInstance Server1 -Name MyCredential -Identity "ad\user" -SecurePassword (Get-Credential NoUsernameNeeded).Password

It will create a credential named "MyCredential" that as "ad\user" as identity and a password on server1 if it does not exist.

Example: 2
PS C:\> New-DbaCredential -SqlInstance Server1 -Identity "MyIdentity"

It will create a credential with identity value "MyIdentity" and same name but without a password on server1 if it does not exist.

Example: 3
PS C:\> $params = @{
>>SqlInstance = "Server1"
>>Name = "AzureBackupBlobStore"
>>Identity = "https://<Azure Storage Account Name>.blob.core.windows.net/<Blob Container Name>"
>>SecurePassword = (Get-Credential NoUsernameNeeded).Password # <Azure Storage Account Access Key>
>>}
PS C:\> New-DbaCredential @params

Creates a credential, "AzureBackupBlobStore", on Server1 using the Access Keys for Backup To URL. Identity must be the full URI for the blob container that will be the backup target. The
SecurePassword supplied is one of the two Access Keys for the Azure Storage Account.

Example: 4
PS C:\> $sasParams = @{
>>SqlInstance = "server1"
>>Name = "https://<azure storage account name>.blob.core.windows.net/<blob container>"
>>Identity = "SHARED ACCESS SIGNATURE"
>>SecurePassword = (Get-Credential NoUsernameNeeded).Password # <Shared Access Token>
>>}
PS C:\> New-DbaCredential @sasParams

Create a credential on Server1 using a SAS token for Backup To URL. The Name is the full URI for the blob container that will be the backup target.
The SecurePassword will be the Shared Access Token (SAS), as a SecureString.

Example: 5
PS C:\> $managedIdentityParams = @{
>>SqlInstance = "server1"
>>Name = "https://<azure storage account name>.blob.core.windows.net/<blob container>"
>>Identity = "Managed Identity"
>>}
PS C:\> New-DbaCredential @managedIdentityParams

Create a credential on Server1 using a Managed Identity for Backup To URL. The Name is the full URI for the blob container that will be the backup target.
As no password is needed in this case, we just don't pass the -SecurePassword parameter.

Required Parameters

-SqlInstance

The target SQL Server(s)

Alias
Required True
Pipeline true (ByValue)
Default Value
-Identity

The Credential Identity

Alias CredentialIdentity
Required True
Pipeline false
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Name

The Credential name

Alias
Required False
Pipeline false
Default Value $Identity
-SecurePassword

Secure string used to authenticate the Credential Identity

Alias Password
Required False
Pipeline false
Default Value
-MappedClassType

Sets the class associated with the credential.

Alias
Required False
Pipeline false
Default Value None
Accepted Values CryptographicProvider,None
-ProviderName

Sets the name of the provider

Alias
Required False
Pipeline false
Default Value
-Force

If credential exists, drop and recreate

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command

Alias cf
Required False
Pipeline false
Default Value