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

Evaluating a policy


In this recipe, we will evaluate a policy against our SQL Server instance.

Getting ready

In this recipe, we will evaluate the xp_cmdshell must be disabled policy, which we created in a previous recipe. We also want to export this to an XML file and there are two different ways of evaluating the policy. Use the Exporting a policy recipe to export the xp_cmdshell must be disabled policy and save it in C:\Temp. Alternatively, you can perform the following steps:

  1. Log in to SQL Server Management Studio.

  2. Go to Management | Policy Management and select Policies.

  3. Right-click on the xp_cmdshell must be disabled policy and select Export Policy.

  4. Save this policy in C:\Temp.

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

How to do it...

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

  1. Open PowerShell ISE as an administrator.

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

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