How to Delete a Security Scope
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
The following example shows how to delete a security scope in System Center 2012 R2 Configuration Manager by using the SMS_SecuredCategory class.
To delete a security scope
Set up a connection to the SMS Provider.
Load the existing security scope by using the SMS_SecuredCategory WMI class
Delete the security scope by using the delete method.
Example
The following example deletes a security scope by identifier:
Sub DeleteSecurityScope(connection, scopeId)
Dim scope
' Get the existing scope by identifier.
Set scope = connection.Get("SMS_SecuredCategory.CategoryID='" & scopeId & "'")
' Make sure we are allowed to delete this scope.
If (scope.IsBuiltIn) Then
Err.Raise 1, "DeleteSecurityScope", "Deleting a built-in security scope is not allowed."
Else
scope.Delete_
End If
End Sub
public void DeleteSecurityScope(WqlConnectionManager connection, string scopeId) { // Get the existing scope by identifier. IResultObject secScope = connection.GetInstance("SMS_SecuredCategory.CategoryID='" + scopeId + "'"); // Make sure we are allowed to delete this scope. if (secScope.Properties["IsBuiltIn"].BooleanValue == true) throw new System.Exception("Deleting a built-in security scope is not allowed."); else secScope.Delete(); }
Compiling the Code
The C# example requires:
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
scopeId
String
The identifier of the security scope to delete.