Creating a condition
In this recipe, we will create a condition to be later used programmatically for a policy.
Getting ready
In this recipe, we will
create a condition called xp_cmdshell is disabled
, which checks the Server Security
facet, XPCmdShellEnabled
.
How to do it...
Open the PowerShell ISE. Go to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a new connection object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking $connectionstring ="server='KERRIGAN';Trusted_Connection=true" $conn = New-Object Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection($connectionstring) $policystore = New-Object Microsoft.SqlServer.Management.DMF.PolicyStore($conn)
Add the following script and run:
$conditionName = "xp_cmdshell is disabled" if ($policystore.Conditions[$conditionName]) { $policystore.Conditions[$conditionName].Drop() } #facet name #we are retrieving facet name in this manner because #some facet...