< Back

Restore-DbaDbCertificate

Mon Jan 13, 2020 1:36 pm

NAME Restore-DbaDbCertificate



SYNOPSIS

Imports certificates from .cer files using SMO.





SYNTAX

Restore-DbaDbCertificate [-SqlInstance] <DbaInstanceParameter> [[-SqlCredential] <Pscredential>] [-Path]

<System.Object[]> [[-EncryptionPassword] <Securestring>] [[-Database] <String>] [[-SecurePassword] <Securestring>]

[-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Imports certificates from.cer files using SMO.





PARAMETERS

-Database [<String>]

The database where the certificate imports into. 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



-EncryptionPassword [<Securestring>]

If specified this will be used to encrypt the private key.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Path [<System.Object[]>]

The Path the contains the certificate and private key files. The path can be a directory or a specific

certificate.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SecurePassword [<Securestring>]

Secure string used to decrypt the private 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 [<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: Migration, Certificate

Author: Jess Pomfret (@jpomfret), jesspomfret.com



Website: https://dbatools.io

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

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



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



PS C:\\>$securepass = Get-Credential usernamedoesntmatter | Select-Object -ExpandProperty Password



PS C:\\> Restore-DbaDbCertificate -SqlInstance Server1 -Path \\\\Server1\\Certificates -SecurePassword $securepass



Restores all the certificates in the specified path, password is used to both decrypt and encrypt the private key.

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



PS C:\\>Restore-DbaDbCertificate -SqlInstance Server1 -Path \\\\Server1\\Certificates\\DatabaseTDE.cer -SecurePassword

(Get-Credential usernamedoesntmatter).Password



Restores the DatabaseTDE certificate to Server1 and uses the MasterKey to encrypt the private key.



RELATED LINKS

https://dbatools.io/Restore-DbaDbCertificate