Sdílet prostřednictvím


Přiřazení standardních hodnot konfigurace

V Configuration Manager se pro přiřazení standardních hodnot konfigurace ke kolekci vytvoří instance přiřazení, naplní se minimální sadou požadovaných hodnot a uloží se.

Přiřazení standardních hodnot konfigurace

  1. Nastavte připojení k poskytovateli serveru SMS.

  2. Vytvořte instanci objektu SMS_BaselineAssignment.

  3. Vyplňte vlastnosti instance.

  4. Uložte novou SMS_BaselineAssignment instanci.

Příklad

Následující příklady kódu ukazují, jak vytvořit instanci přiřazení podle směrného plánu.

Informace o volání ukázkového kódu najdete v tématu Volání Configuration Manager fragmentů kódu.


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.");  

}  

Ukázková metoda má následující parametry:

Parametr Typ Popis
- connection
- swbemServices
-Spravované: WqlConnectionManager
- VBScript: SWbemServices
Platné připojení k poskytovateli serveru SMS.
applyToSubTargets -Spravované: Boolean
-Vbscript: Boolean
true a použijete přiřazení položky konfigurace na podsbídku.
assignmentAction -Spravované: Integer
-Vbscript: Integer
Akce přidružená k přiřazení položky konfigurace
assignmentName -Spravované: String
-Vbscript: String
assignmentName
assignmentDescription -Spravované: String
-Vbscript: String
Název místního přiřazení.
desiredConfigType -Spravované: String
-Vbscript: String
Typ položky konfigurace.
distributionPointLocality -Spravované: Integer
-Vbscript: Integer
Příznaky, které určují, jak klient získá distribuční body podle umístění distribučního bodu.
evaluationSchedule -Spravované: String
-Vbscript: String
Plán vyhodnocení zadání.
logComplianceToWinEvent -Spravované: Boolean
-Vbscript: Boolean
true a protokolovat stav dodržování předpisů do protokolů událostí Systému Windows.
notifyUser -Spravované: Boolean
-Vbscript: Boolean
true upozorňovat uživatele, když je k dispozici položka konfigurace.
sendDetailedNonComplianceStatus -Spravované: Boolean
-Vbscript: Boolean
true a odešlete podrobnou zprávu o stavu nedodržování předpisů.
startTime -Spravované: String
-Vbscript: String
Datum a čas, kdy bylo původně nabídnuto přiřazení položky konfigurace.
suppressReboot -Spravované: Integer
-Vbscript: Integer
Hodnota označující, jestli klient nemá restartovat počítač, pokud po použití položky konfigurace čeká na restartování.
targetCollectionID -Spravované: String
-Vbscript: String
Identifikátor kolekce, na kterou je přiřazení zaměřeno.
useGMTTimes -Spravované: Boolean
-Vbscript: Boolean
true pokud jsou časy a plány ve standardu UTC (Universal Coordinated Time).
baselineID - Spravované: Integer Pole
- VBScript: Integer Pole
Pole ID položek konfigurace, na které přiřazení cílí

Kompilace kódu

Obory názvů

Systému

System.collections.generic

System.componentmodel

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Sestavení

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robustní programování

Další informace o zpracování chyb najdete v tématu Informace o chybách Configuration Manager.

Zabezpečení rozhraní .NET Framework

Další informace o zabezpečení Configuration Manager aplikací najdete v tématu Configuration Manager správa na základě rolí.

Viz taky

Informace o standardních hodnotách konfigurace a položkách konfigurace
Přehled objektůJak se připojit k poskytovateli Configuration Manager pomocí spravovaného kódu
Připojení k poskytovateli Configuration Manager pomocí rozhraní WMI
Serverová třída služby WMI SMS_BaselineAssignment