Listing policies
In this recipe, we will list policies deployed in our SQL Server instance.
Getting ready
Check which policies are being used in your environment using SQL Server Management Studio. Connect to SSMS, and expand Management | Policy Management | Policies:
These are the same policies you should get when you run the PowerShell script in this recipe.
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Add the following script and run:
$connectionstring = "server='KERRIGAN';Trusted_Connection=true" $conn = New-Object Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection($connectionstring) #NOTE notice how the namespace is still called DMF #DMF - declarative management framework #DMF was the old reference to Policy Based Management $PolicyStore = New-Object Microsoft.SqlServer.Management.DMF.PolicyStore($conn) ...