How to Associate an Object with 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
Tip |
|---|
To assign multiple objects to a scope, use the AddMemberships Method in Class SMS_SecuredCategoryMembership. |
To assign an object a security scope
Set up a connection to the SMS Provider.
Determine the object’s key property identifier.
Determine the object type identifier.
Create a new instance of the SMS_SecuredCategoryMembership WMI class, setting the scope identifier, object key, and object type values.
Save the SMS_SecuredCategoryMembership object instance.
Example
The following code example assigns a scope identifier to a package:
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
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(); }
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.
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.