Partager via


How to Assign Configuration Baselines

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

In Microsoft System Center Configuration Manager 2007, to assign a configuration baseline to a collection, an assignment instance is created, populated with a minimum set of required values, and saved.

Example

The following code examples show how to create an instance of a baseline assignment.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

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

}

Compiling the Code

Namespaces

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Concepts

About Configuration Baselines and Configuration Items
How to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using WMI
SMS_BaselineAssignment Server WMI Class