Tip
To assign multiple objects to a scope, use the AddMemberships Method in Class SMS_SecuredCategoryMembership.

To assign an object a security scope

  1. Set up a connection to the SMS Provider.

  2. Determine the object’s key property identifier.

  3. Determine the object type identifier.

  4. Create a new instance of the SMS_SecuredCategoryMembership WMI class, setting the scope identifier, object key, and object type values.

  5. Save the SMS_SecuredCategoryMembership object instance.

Example

The following code example assigns a scope identifier to a package:

Visual Basic Script  Copy Code
Sub AddObjectScope(connection, scopeId, objectKey, objectTypeId)
	Dim assignment
	' Create a new instance of the scope assignment.
	Set assignment = connection.Get("SMS_SecuredCategoryMembership").SpawnInstance_()
	' Configure the assignment
	assignment.CategoryID = scopeId
	assignment.ObjectKey = objectKey
	assignment.ObjectTypeID = objectTypeId
	' Commit the assignment
	assignment.Put_
	End Sub
C#  Copy Code
public void AddObjectScope(WqlConnectionManager connection, string scopeId, string objectKey, int objectTypeId)
{
	// Create a new instance of the scope assignment.
	IResultObject assignment = connection.CreateInstance("SMS_SecuredCategoryMembership");
	// Configure the assignment
	assignment.Properties["CategoryID"].StringValue = scopeId;
	assignment.Properties["ObjectKey"].StringValue = objectKey;
	assignment.Properties["ObjectTypeID"].IntegerValue = objectTypeId;
	// Commit the assignment
	assignment.Put();
}

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.

objectKey

String

The key property value of the object to assign a scope to.

objectTypeId

Integer

The type identifier of the object referenced in the objectKey parameter.

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