How to Assign Configuration Baselines

W Configuration Manager, aby przypisać konfigurację odniesienia do kolekcji, tworzone jest wystąpienie przypisania, wypełniane minimalnym zestawem wymaganych wartości i zapisywane.

Aby przypisać konfigurację odniesienia

  1. Skonfiguruj połączenie z dostawcą programu SMS.

  2. Utwórz wystąpienie elementu SMS_BaselineAssignment.

  3. Wypełnij właściwości wystąpienia.

  4. Zapisz nowe SMS_BaselineAssignment wystąpienie.

Przykład

W poniższych przykładach kodu pokazano, jak utworzyć wystąpienie przypisania punktu odniesienia.

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


Sub DCMCreateAssignment(swbemServices,                     _  
                        baselineID,                        _  
                        applyToSubTargets,                 _  
                        assignmentAction,                  _  
                        assignmentName,                    _  
                        assignmentDescription,             _  
                        desiredConfigType,                 _  
                        distributionPointLocality,         _  
                        evaluationSchedule,                _  
                        logComplianceToWinEvent,           _  
                        notifyUser,                        _  
                        sendDetailedNonComplianceStatus,   _  
                        startTime,                         _  
                        suppressReboot,                    _  
                        targetCollectionID,                _  
                        useGMTTimes)  

' Create new assignment object.  
set newAssignment = swbemServices.Get("SMS_BaselineAssignment").SpawnInstance_()        

' Assign variable values to assignment properties.  
'    //  
'    // The following properties are set by the provider on put():  
'    //     AssignmentID  
'    //     AssignmentUniqueID  
'    //     SourceSite  
'    //     CreationTime  

newAssignment.ApplyToSubTargets = applyToSubTargets   
newAssignment.AssignmentAction = assignmentAction   
newAssignment.AssignmentName = assignmentName   
newAssignment.AssignmentDescription = assignmentDescription   
newAssignment.DesiredConfigType = desiredConfigType   
newAssignment.DPLocality = distributionPointLocality   
newAssignment.EvaluationSchedule = evaluationSchedule   
newAssignment.LogComplianceToWinEvent = logComplianceToWinEvent   
newAssignment.NotifyUser = notifyUser   
newAssignment.SendDetailedNonComplianceStatus = sendDetailedNonComplianceStatus   
newAssignment.StartTime = startTime   
newAssignment.SuppressReboot = suppressReboot   
newAssignment.TargetCollectionID = targetCollectionID   
newAssignment.UseGMTTimes = useGMTTimes   
newAssignment.AssignedCIs = Array(baselineID)   

' Save assignment.  
newAssignment.Put_  

Wscript.Echo " "  
Wscript.Echo "Created new assignment."      

End Sub  


public void DCMCreateAssignment(WqlConnectionManager connection,  
                                bool applyToSubTargets,  
                                int assignmentAction,  
                                string assignmentName,  
                                string assignmentDescription,  
                                string desiredConfigType,  
                                int distributionPointLocality,  
                                string evaluationSchedule,  
                                bool logComplianceToWinEvent,  
                                bool notifyUser,  
                                bool sendDetailedNonComplianceStatus,  
                                string startTime,  
                                int suppressReboot,  
                                string targetCollectionID,  
                                bool useGMTTimes,  
                                int baselineID)  
{  

    // Set required variables.   
    // Set AssignedCIs like array with a known baseline id (this is the initial creation of the assignment, so no existing values).  
    int[] arrayBaselineNumbers = new int[] { baselineID };  

    try  
    {  
        // Create new assignment object.  
        IResultObject newAssignment = connection.CreateInstance("SMS_BaselineAssignment");  

        // Assign variable values to assignment properties.  
        //  
        // The following properties are set by the provider on put():  
        //     AssignmentID  
        //     AssignmentUniqueID  
        //     SourceSite  
        //     CreationTime  
        newAssignment["ApplyToSubTargets"].BooleanValue = applyToSubTargets;  
        newAssignment["AssignmentAction"].IntegerValue = assignmentAction;  
        newAssignment["AssignmentName"].StringValue = assignmentName;  
        newAssignment["AssignmentDescription"].StringValue = assignmentDescription;  
        newAssignment["DesiredConfigType"].StringValue = desiredConfigType;  
        newAssignment["DPLocality"].IntegerValue = distributionPointLocality;  
        newAssignment["EvaluationSchedule"].StringValue = evaluationSchedule;  
        newAssignment["LogComplianceToWinEvent"].BooleanValue = logComplianceToWinEvent;  
        newAssignment["NotifyUser"].BooleanValue = notifyUser;  
        newAssignment["SendDetailedNonComplianceStatus"].BooleanValue = sendDetailedNonComplianceStatus;  
        newAssignment["StartTime"].StringValue = startTime;  
        newAssignment["SuppressReboot"].IntegerValue = suppressReboot;  
        newAssignment["TargetCollectionID"].StringValue = targetCollectionID;  
        newAssignment["AssignedCIs"].IntegerArrayValue = arrayBaselineNumbers;  
        newAssignment["UseGMTTimes"].BooleanValue = useGMTTimes;  

        // Save assignment object.  
        newAssignment.Put();  
    }  
    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to create new assignment." + "\\n" + ex.Message);  
        throw;  
    }  

    Console.WriteLine("Created new assignment.");  

}  

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

Parametr Wpisać Opis
- connection
- swbemServices
-Zarządzane: WqlConnectionManager
- VBScript: SWbemServices
Prawidłowe połączenie z dostawcą programu SMS.
applyToSubTargets -Zarządzane: Boolean
-Vbscript: Boolean
true aby zastosować przypisanie elementu konfiguracji do podkolumny.
assignmentAction -Zarządzane: Integer
-Vbscript: Integer
Akcja skojarzona z przypisaniem elementu konfiguracji.
assignmentName -Zarządzane: String
-Vbscript: String
assignmentName
assignmentDescription -Zarządzane: String
-Vbscript: String
Nazwa przypisania lokalnego.
desiredConfigType -Zarządzane: String
-Vbscript: String
Typ elementu konfiguracji.
distributionPointLocality -Zarządzane: Integer
-Vbscript: Integer
Flagi określające sposób uzyskiwania punktów dystrybucji przez klienta zgodnie z lokalizacją punktu dystrybucji.
evaluationSchedule -Zarządzane: String
-Vbscript: String
Harmonogram oceny przypisania.
logComplianceToWinEvent -Zarządzane: Boolean
-Vbscript: Boolean
true w celu zarejestrowania stanu zgodności w dziennikach zdarzeń systemu Windows.
notifyUser -Zarządzane: Boolean
-Vbscript: Boolean
true aby powiadomić użytkownika, gdy element konfiguracji jest dostępny.
sendDetailedNonComplianceStatus -Zarządzane: Boolean
-Vbscript: Boolean
true aby wysłać szczegółowy komunikat o stanie niezgodności.
startTime -Zarządzane: String
-Vbscript: String
Data i godzina początkowego przypisania elementu konfiguracji.
suppressReboot -Zarządzane: Integer
-Vbscript: Integer
Wartość wskazująca, czy klient nie powinien ponownie uruchomić komputera, jeśli po zastosowaniu elementu konfiguracji oczekuje na ponowne uruchomienie.
targetCollectionID -Zarządzane: String
-Vbscript: String
Identyfikator kolekcji, do której jest przeznaczone przypisanie.
useGMTTimes -Zarządzane: Boolean
-Vbscript: Boolean
true jeśli godziny i harmonogramy znajdują się w uniwersalnym czasie koordynowanym (UTC).
baselineID — Zarządzane: Integer tablica
- VBScript: Integer Tablica
Tablica identyfikatorów elementów konfiguracji objętych przypisaniem.

Kompilowanie kodu

Obszary nazw

System

System.collections.generic

System.componentmodel

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Zestawu

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

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 konfiguracji odniesienia i elementów konfiguracji
Omówienie obiektówJak nawiązać połączenie z dostawcą Configuration Manager przy użyciu kodu zarządzanego
Jak nawiązać połączenie z dostawcą Configuration Manager przy użyciu usługi WMI
SMS_BaselineAssignment Server WMI Class