How to Associate an Object with a Security Scope
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();
}
The example method has the following parameters:
Parameter |
Type |
Description |
connection |
|
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. |
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
SMS_SecuredCategoryMembership Server WMI Class
How to Create a New Security Scope
How to Delete a Security Scope
How to Remove an Object Association with a Security Scope
SMS_SecuredCategory Server WMI Class