Creating a certificate
This recipe shows how you can create a certificate using PowerShell and SMO.
Getting ready
In this recipe, we will create a certificate called Test Certificate
that is 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 in this recipe is as follows:
CREATE CERTIFICATE [Test Certificate] WITH SUBJECT = N'This is a test certificate.', START_DATE = N'04/10/2015', EXPIRY_DATE = N'04/10/2017'
How to do it...
Let's take a look at the steps required to complete the task:
- Open PowerShell ISE as an administrator.
- Import the
SQLPS
module and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList...