Databases Reference
In-Depth Information
If for some reason the
Drop
method does not work, try to open another Windows PowerShell console and
run the commands again.
You can also use the
ScriptCreate
,
ScriptAlter
,and
ScriptDrop
methods to generate the SQL scripts
that can be used to create, alter, and drop a condition, respectively. The following recreates the
No server
access
condition and generates the scripts for it:
# Create the new condition "No server access"
$sqlConnection
=
New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString
=
"Server
=
PowerPC;Database
=
master;Integrated
Security
=
True"
$storeConnection
=
New-Object Microsoft.SqlServer.Management.Sdk.Sfc.
SqlStoreConnection($sqlConnection)
$store
=
New-Object Microsoft.SqlServer.Management.Dmf.PolicyStore ($storeConnection)
$condition
=
New-Object Microsoft.SqlServer.Management.Dmf.Condition ($store,
'No server access')
$condition.ExpressionNode
=
'@HasAccess
=
False()'
$condition.Facet
=
'Login'
$condition.Create()
# Generate SQL scripts that can be used to create, alter and drop the condition
$condition.ScriptCreate().ToString()
$condition.ScriptAlter().ToString()
$condition.ScriptDrop().ToString()
However, notice that in Figure 12-9 the create and alter scripts are not complete.
Figure 12-9
Search WWH ::
Custom Search