Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating symmetric and asymmetric keys


In this recipe, we will create symmetric and asymmetric keys.

Getting ready

In this recipe, we will use the TestDB database. If you don't already have this database, log in to SQL Server Management Studio and execute the following T-SQL code:

IF DB_ID('TestDB') IS NULL
CREATE DATABASE TestDB
GO

We will also work with a database user called eric in our TestDB database. This user will map to the SQL login eric. Feel free to create this user using the Creating a database user recipe of Chapter 4, Security, as a reference. Alternatively, execute the following T-SQL code from SQL Server Management Studio or replace it with an existing login/database user in your system:

Use TestDB
GO
CREATE USER [eric]
FOR LOGIN [eric]

How to do it...

Let's take a look at the steps required to complete the task:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module and create a new SMO Server object as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking...