How to Run an Action on a Specific Computer
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. The static method on the class runs the action on a set of specified computers.
To run an action on a specific out of band computer
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Get the SMS_Collection class object.
-
Call the AMTOperateForMachines method on the SMS_Collection class object and supply the action to run on the machines.
Example
The following example method runs an action on the SMS_Collection class.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
public void RunAmtAction(WqlConnectionManager connection, List<int> machineResourceIds, int actionType) { try { IResultObject classObj = connection.GetClassObject("SMS_Collection"); Dictionary<string, object> inParams = new Dictionary<string, object>(); Console.WriteLine("Running AMT action: " + actionType.ToString()); inParams.Add("ResourceIDs", machineResourceIds.ToArray()); inParams.Add("opcode", actionType); classObj.ExecuteMethod("AMTOperateForMachines", inParams); } catch (SmsException ex) { Console.WriteLine("Failed to run AMT action. Error: " + ex.Message); throw; } }
Function RunAmtAction(connection, machineResourceIds, actionType)
On Error Resume Next
Dim classObj: Set classObj = connection.Get("SMS_Collection")
Dim inParams: Set inParams = classObj.Methods_("AMTOperateForMachines").InParameters.SpawnInstance_()
Dim outParams
inParams.Properties_.Item("Opcode") = actionType
inParams.Properties_.Item("ResourceIDs") = machineResourceIds
Set outParams = connection.ExecMethod("SMS_Collection", "AMTOperateForMachines", 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. |
||||||||||||||||||||||||||
|
machineResourceIds |
Managed: List<int> VBScript: Long() |
Array of SMS_R_System.ResourceID values. |
||||||||||||||||||||||||||
|
actionType |
Managed: int 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.