Udostępnij za pośrednictwem


Jak utworzyć skojarzenie między dwoma komputerami w Configuration Manager

Skojarzenie między komputerem referencyjnym i docelowym w Configuration Manager jest tworzone przez wywołanie metody AddAssociation w klasie SMS_StateMigration.

Uwaga

Aby usunąć skojarzenie, należy wywołać metodę DeleteAssociation w klasie SMS_StateMigration .

Aby utworzyć skojarzenie między dwoma komputerami

  1. Skonfiguruj połączenie z dostawcą programu SMS. Aby uzyskać więcej informacji, zobacz Podstawy dostawcy programu SMS.

  2. Wywołaj metodę AddAssociation w klasie SMS_StateMigration.

Przykład

Poniższa przykładowa metoda dodaje skojarzenie między komputerem źródłowym i referencyjnym.

Aby uzyskać informacje na temat wywoływania przykładowego kodu, zobacz Wywoływanie fragmentów kodu Configuration Manager.

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

Przykładowa metoda ma następujące parametry:

Parametr Wpisać Opis
connection -Zarządzane: WqlConnectionManager
- VBScript: SWbemServices
Prawidłowe połączenie z dostawcą programu SMS.
referenceComputerResourceID -Zarządzane: Integer
-Vbscript: Integer
Identyfikator zasobu Configuration Manager dla komputera odniesienia. Jest to dostępne we SMS_R_System właściwości klasy ResourceId dla komputera.
destinationComputerResourceID -Zarządzane: Integer
-Vbscript: Integer
Identyfikator zasobu Configuration Manager komputera docelowego. Jest to dostępne we SMS_R_System właściwości klasy ResourceId dla komputera.

Kompilowanie kodu

Przykład języka C# ma następujące wymagania dotyczące kompilacji:

Obszary nazw

System

System.collections.generic

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Zestawu

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Niezawodne programowanie

Aby uzyskać więcej informacji na temat obsługi błędów, zobacz Informacje o błędach Configuration Manager.

zabezpieczenia .NET Framework

Aby uzyskać więcej informacji na temat zabezpieczania aplikacji Configuration Manager, zobacz Configuration Manager administracja oparta na rolach.

Zobacz też

Informacje o metodzie AddAssociation zarządzania komputerem wdrożenia systemu operacyjnegow klasie SMS_StateMigration
DeleteAssociation, metoda w klasie SMS_StateMigration