How to Create an Association Between Two Computers in Configuration Manager

 

Updated: November 1, 2013

Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager

You create an association between a reference and destination computer, in System Center 2012 R2 Configuration Manager, by calling the AddAssociation Method in Class SMS_StateMigration.

System_CAPS_noteNote

You call the DeleteAssociation Method in Class SMS_StateMigration to delete an association.

To create an association between two computers

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

Example

The following example method adds an association between a source and reference computer.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub AssociateComputer(connection, referenceComputerResourceId, destinationComputerResourceId)

    Dim stateMigrationClass
    Dim inParams
    Dim outParams

    ' Get the state migration class.
    Set stateMigrationClass = connection.Get("SMS_StateMigration")

    ' Set up the parameters.
    Set inParams = _
      stateMigrationClass.Methods_("AddAssociation").InParameters.SpawnInstance_
    inParams.SourceClientResourceID = referenceComputerResourceId
    inParams.RestoreClientResourceID = destinationComputerResourceId

    ' Call the method.
    Set outParams = _
      connection.ExecMethod( "SMS_StateMigration", "AddAssociation", inParams)   

   End Sub
public void AssociateComputer(
    WqlConnectionManager connection, 
    int referenceComputerResourceId, 
    int destinationComputerResourceId)
{
    try
    {
        // Set up the reference and destination computer in parameters.
        Dictionary<string, object> inParams = new Dictionary<string, object>();
        inParams.Add("SourceClientResourceID", referenceComputerResourceId);
        inParams.Add("RestoreClientResourceID", destinationComputerResourceId);

        // Create the computer association.
       connection.ExecuteMethod("SMS_StateMigration", "AddAssociation", inParams);
    }
    catch (SmsException e)
    {
        Console.WriteLine("failed to make the association" + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter

Type

Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

referenceComputerResourceID

  • Managed: Integer

  • VBScript: Integer

The Configuration Manager resource identifier for the reference computer. This is available from SMS_R_System class ResourceId property for the computer.

destinationComputerResourceID

  • Managed: Integer

  • VBScript: Integer

The Configuration Manager resource identifier for the destination computer. This is available from SMS_R_System class ResourceId property for the computer.

Compiling the Code

The C# example has the following compilation requirements:

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

.NET Framework Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

Show: