Importing a policy

This recipe will show you how you can import a policy stored as an XML file into SQL Server.

Getting ready

In this recipe, we will use an XML policy that comes with the default SQL Server installation. This policy is called Database Page Verification.xml and is stored in C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Policies\DatabaseEngine\1033.

Feel free to substitute this with a policy that is available in your system.

How to do it...

These are the steps required to import a policy using PowerShell:

  1. Open PowerShell ISE as an administrator.
  2. Import the SQLPS module:
    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Add the following script and run it:
    $connectionString = "server='localhost';Trusted_Connection=true" ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.