How to Run an Action on a Collection
Updated: October 28, 2009
Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2
You can run an action on an out of band computer, in Microsoft System Center Configuration Manager 2007, by using the SMS_Collection class. Two separate methods exist on the SMS_Collection class, one on the instance, and one on the class itself.
To run an action on a collection of out of band computers
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Query the SMS Provider for the SMS_Collection class instance that you want to run an action on.
-
Call the SMS_Collection class AMTOperateForCollection method to run an action on the collection.
Example
The following example method runs an action on the supplied SMS_Collection class instance.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
public void RunAmtAction(WqlConnectionManager connection, IResultObject smsCollection, int actionType) { try { Console.WriteLine("Running AMT action: " + actionType.ToString()); Dictionary<string, object> inParams = new Dictionary<string, object>(); inParams.Add("opcode", actionType); smsCollection.ExecuteMethod("AMTOperateForCollection", inParams); } catch (SmsException ex) { Console.WriteLine("Failed to run AMT action. Error: " + ex.Message); throw; } }
Function RunAmtAction(connection, smsCollection, actionType)
On Error Resume Next
Dim inParams: Set inParams = smsCollection.Methods_("AMTOperateForCollection").InParameters.SpawnInstance_
Dim outParams
inParams.opcode = actionType
Set outParams = smsCollection.ExecMethod_("AMTOperateForCollection", inParams)
If Err.Number <> 0 Then
RunAmtAction = False
Else
RunAmtAction = True
End If
On Error Goto 0
End Function
The example method has the following parameters:
| Parameter | Type | Description | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
connection |
Managed: WqlConnectionManager VBScript: SWbemServices |
A valid connection to the provider. |
||||||||||||||||||||||||||
|
smsCollection |
Managed: IResultObject VBScript: SWbemObject |
Instance of an SMS_Connection WMI class |
||||||||||||||||||||||||||
|
actionType |
Managed: integer VBScript: long |
Action to execute on the collection members. The following table provides the list of supported actions:
|
Compiling the Code
This C# example requires:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
Security
For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.