Condividi tramite


Come assegnare linee di base di configurazione

In Configuration Manager, per assegnare una baseline di configurazione a una raccolta, viene creata un'istanza di assegnazione, popolata con un set minimo di valori obbligatori e salvata.

Per assegnare le baseline di configurazione

  1. Configurare una connessione al provider SMS.

  2. Creare un'istanza di SMS_BaselineAssignment.

  3. Popolare le proprietà dell'istanza.

  4. Salvare la nuova SMS_BaselineAssignment istanza di .

Esempio

Gli esempi di codice seguenti illustrano come creare un'istanza di un'assegnazione di base.

Per informazioni sulla chiamata del codice di esempio, vedere Chiamata di frammenti di codice 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.");  

}  

Il metodo di esempio include i parametri seguenti:

Parametro Tipo Descrizione
- connection
- swbemServices
-Gestito: WqlConnectionManager
- VBScript: SWbemServices
Connessione valida al provider SMS.
applyToSubTargets -Gestito: Boolean
-Vbscript: Boolean
true per applicare l'assegnazione dell'elemento di configurazione a una sottoraccolta.
assignmentAction -Gestito: Integer
-Vbscript: Integer
Azione associata all'assegnazione dell'elemento di configurazione.
assignmentName -Gestito: String
-Vbscript: String
assignmentName
assignmentDescription -Gestito: String
-Vbscript: String
Nome dell'assegnazione locale.
desiredConfigType -Gestito: String
-Vbscript: String
Tipo dell'elemento di configurazione.
distributionPointLocality -Gestito: Integer
-Vbscript: Integer
Flag che determinano il modo in cui il client ottiene i punti di distribuzione, in base alla località del punto di distribuzione.
evaluationSchedule -Gestito: String
-Vbscript: String
Pianificazione della valutazione dell'assegnazione.
logComplianceToWinEvent -Gestito: Boolean
-Vbscript: Boolean
true per registrare lo stato di conformità nei log eventi di Windows.
notifyUser -Gestito: Boolean
-Vbscript: Boolean
true per notificare all'utente quando è disponibile un elemento di configurazione.
sendDetailedNonComplianceStatus -Gestito: Boolean
-Vbscript: Boolean
true per inviare un messaggio dettagliato sullo stato di non conformità.
startTime -Gestito: String
-Vbscript: String
Data e ora in cui è stata inizialmente offerta l'assegnazione dell'elemento di configurazione.
suppressReboot -Gestito: Integer
-Vbscript: Integer
Valore che indica se il client non deve riavviare il computer, se è presente un riavvio in sospeso dopo l'applicazione dell'elemento di configurazione.
targetCollectionID -Gestito: String
-Vbscript: String
Identificatore della raccolta a cui è destinata l'assegnazione.
useGMTTimes -Gestito: Boolean
-Vbscript: Boolean
true se gli orari e le pianificazioni sono in formato UTC (Universal Coordinated Time).
baselineID - Gestito: Integer array
- VBScript: Integer Matrice
Matrice di ID per gli elementi di configurazione di destinazione dell'assegnazione.

Compilazione del codice

Namespaces

Sistema

System.collections.generic

System.ComponentModel

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Programmazione efficiente

Per altre informazioni sulla gestione degli errori, vedere Informazioni sugli errori di Configuration Manager.

Sicurezza di .NET Framework

Per altre informazioni sulla protezione delle applicazioni Configuration Manager, vedere Configuration Manager'amministrazione basata sui ruoli.

Vedere anche

Informazioni sulle baseline di configurazione e sugli elementi di configurazione
Panoramica degli oggettiCome connettersi a un provider di Configuration Manager tramite codice gestito
Come connettersi a un provider di Configuration Manager tramite WMI
Classe WMI del server SMS_BaselineAssignment