How to Run an Action on a Collection

System Center

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

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Query the SMS Provider for the SMS_Collection class instance that you want to run an action on.

  3. 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:

 

Action Type Value Description

1

Wake up the computer.

2

Restart the computer.

3

Shut down the computer.

8

Discover the BMC.

16

Re-inventory the BMC.

32

Partial unprovision.

64

Perform a full unprovision.

544

Perform a full unprovision suppress notifications.

576

Partially unprovision the computer and suppress notifications.

128

Provision the computer.

256

Reprovision the computer.

1024

Unsuppress.

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.

Show: