How to Delete a Security Scope

 

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

  1. Set up a connection to the SMS Provider.

  2. Load the existing security scope by using the SMS_SecuredCategory WMI class

  3. 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();
}

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.

Compiling the Code

The C# example requires:

Namespaces

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

See Also

Security Scope Management
How to Create a New Security Scope
How to Associate an Object with a Security Scope
How to Remove an Object Association with a Security Scope
SMS_SecuredCategory Server WMI Class