Book Image

PowerShell for SQL Server Essentials

By : Donabel Santos
Book Image

PowerShell for SQL Server Essentials

By: Donabel Santos

Overview of this book

Table of Contents (15 chapters)
PowerShell for SQL Server Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Implementing Reusability with Functions and Modules
Index

Policies


We can check out policies in a SQL Server instance as well, by using PowerShell. Instead of using SMO, we can use the SQLSERVER PSDrive. You can first change your location to the SQLPolicy node:

Set-Location "SQLSERVER:\SQLPolicy\YourSqlServerMachineName"

You can use dir or Get-ChildItem to navigate to the available instances:

Change the location to the instance you are working with. When you list the current items, you should find all the policy-related objects:

If you navigate to Policies, you will be able to see all the policies that are currently installed in the instance (if you have any already installed):

There are more properties and methods to a Policy object, so you can use the Get-Member cmdlet to explore. Just before the list of properties and methods, you should also find that each policy is a Microsoft.SqlServer.Management.Dmf.Policy object. Knowing this information will enable you to work with policies programmatically, the same way we've used SMO in previous sections...