< Back

New-DbaDbAsymmetricKey

Mon Jan 13, 2020 12:49 pm

NAME New-DbaDbAsymmetricKey



SYNOPSIS

Creates a new database asymmetric key





SYNTAX

New-DbaDbAsymmetricKey [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

[[-SqlCredential] <Pscredential>] [[-Name] <System.String[]>] [[-Database] <System.String[]>] [[-SecurePassword]

<Securestring>] [[-Owner] <String>] [[-KeySource] <String>] [[-KeySourceType] <String>] [[-InputObject]

<Microsoft.SqlServer.Management.Smo.Database[]>] [[-Algorithm] <String>] [-EnableException <Switch>]

[<CommonParameters>]





DESCRIPTION

Creates a new database asymmetric key. If no database is specified, the asymmetric key will be created in master.





PARAMETERS

-Algorithm [<String>]

The algorithm used to generate the key. Can be one of RSA512, RSA1024, RSA1024, RSA2048, RSA3072 or RSA4096.

If not specified RSA2048 is the default

This value will be ignored when KeySource is supplied, as the algorithm is embedded in the KeySource



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.String[]>]

The database where the asymmetric key will be created. Defaults to master.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]

Enables piping from Get-DbaDatabase



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-KeySource [<String>]

The path to the Executable, File or Assembly to be passed in.

The path is parsed by the SQL Server instance, so needs to visiable to the instance



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-KeySourceType [<String>]

The source of external keys loaded in, can be one of Executable, File or Assemnly

We do not currently support Provider



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Name [<System.String[]>]

Optional name to create the asymmetric key. Defaults to database name.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Owner [<String>]

User within the database who will own the key. Defaults to the user creating the key if not specified. User

must exist withing the database already



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecurePassword [<Securestring>]

Optional password - if no password is supplied, the password will be protected by the master key



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

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



NOTES





Tags: asymmetrickey

Author: Stuart Moore (@napalmgram), stuart-moore.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>New-DbaDbAsymmetricKey -SqlInstance Server1



You will be prompted to securely enter your password, then an asymmetric key will be created in the master

database on server1 if it does not exist.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>New-DbaDbAsymmetricKey -SqlInstance Server1 -Database db1 -Confirm:$false



Suppresses all prompts to install but prompts to securely enter your password and creates an asymmetric key in the

'db1' database

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>New-DbaDbAsymmetrickKey -SqlInstance Server1 -Database enctest -KeySourceType File -KeySource

c:\\keys\\NewKey.snk -Name BackupKey -Owner KeyOwner



Installs the key pair held in NewKey.snk into the enctest database creating an AsymmetricKey called BackupKey,

which will be owned by KeyOwner



RELATED LINKS