Creating a certificate
This recipe demonstrates how you can create a certificate using PowerShell and SMO.
Getting ready
In this recipe, we will create a certificate called Test Certificate
, protected by the database master key. You will need to make sure that the database master key has been created first for the database.
The T-SQL equivalent of what we are trying to accomplish is:
CREATE CERTIFICATE [Test Certificate] WITH SUBJECT = N'This is a test certificate.', START_DATE = N'02/10/2012', EXPIRY_DATE = N'01/01/2015'
How to do it...
Let's list the steps required to complete the task.
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a new SMO Server object:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following...