dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


New-DbaDatabaseMasterKey

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

Screenshots

dbatools-New-DbaDatabaseMasterKey

Examples

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

New-DbaDatabaseMasterKey -SqlInstance Server1

Suppresses all prompts to install but prompts to securely enter your password and creates a master key in the ‘db1’ database.

New-DbaDatabaseMasterKey -SqlInstance Server1 -Database db1 -Confirm:$false

Author

This command was created by Chrissy LeMaire. You can find Chrissy on Twitter and his blog.

Get-Help

From PowerShell, execute Get-Help New-DbaDatabaseMasterKey -Detailed for more information on this function.

Source Code

Want to see the source code? View New-DbaDatabaseMasterKey.ps1 on GitHub
 

Related commands