commands

^

New-DbaCredential

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

 

Synopsis

Creates a new SQL Server credential

Description

Creates a new credential

Syntax

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

 

Examples

 

Example: 1
PS C:\> New-DbaCredential -SqlInstance Server1

You will be prompted to securely enter your password, then a credential will be created in the master database on server1 if it does not exist.

Example: 2
PS C:\> New-DbaCredential -SqlInstance Server1 -Confirm:$false

Suppresses all prompts to install but prompts to securely enter your password and creates a credential on Server1.

Example: 3
PS C:\> $params = @{
>>SqlInstance = "Server1"
>>Name = "AzureBackupBlobStore"
>>Identity = "https://<Azure Storage Account Name>.blob.core.windows.net/<Blob Container Name>"
>>SecurePassword = (ConvertTo-SecureString '<Azure Storage Account Access Key>' -AsPlainText -Force)
>>}
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 = (ConvertTo-SecureString '<Shared Access Token>' -AsPlainText -Force)
>>}
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.

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

 

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.