![]() |
---|
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:
Visual Basic Script | ![]() |
---|---|
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# | ![]() |
---|---|
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 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.