Dela via


Så här skapar du en association mellan två datorer i Configuration Manager

Du skapar en association mellan en referens- och måldator i Configuration Manager genom att anropa metoden AddAssociation i Class SMS_StateMigration.

Obs!

Du anropar metoden DeleteAssociation i klass SMS_StateMigration för att ta bort en association.

Så här skapar du en association mellan två datorer

  1. Konfigurera en anslutning till SMS-providern. Mer information finns i grunderna för SMS-provider.

  2. Anropa metoden AddAssociation i class SMS_StateMigration.

Exempel

Följande exempelmetod lägger till en association mellan en käll- och referensdator.

Information om hur du anropar exempelkoden finns i Anropa Configuration Manager kodfragment.

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;  
    }  
}  

Exempelmetoden har följande parametrar:

Parameter Typ Beskrivning
connection -Hanterade: WqlConnectionManager
– VBScript: SWbemServices
En giltig anslutning till SMS-providern.
referenceComputerResourceID -Hanterade: Integer
-Vbscript: Integer
Referensdatorns Configuration Manager resursidentifierare. Detta är tillgängligt från SMS_R_System klassegenskapen ResourceId för datorn.
destinationComputerResourceID -Hanterade: Integer
-Vbscript: Integer
Måldatorns Configuration Manager resursidentifierare. Detta är tillgängligt från SMS_R_System klassegenskapen ResourceId för datorn.

Kompilera koden

C#-exemplet har följande kompileringskrav:

Namnområden

System

System.Collections.Generic

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Församlingen

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust programmering

Mer information om felhantering finns i Om Configuration Manager fel.

.NET Framework Säkerhet

Mer information om hur du skyddar Configuration Manager program finns i Configuration Manager rollbaserad administration.

Se även

Om operativsystemets distributionsdatorhanteringAddAssociation-metod i klass SMS_StateMigration
DeleteAssociation-metod i klass SMS_StateMigration