How to Assign Configuration Baselines
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
In System Center 2012 R2 Configuration Manager, to assign a configuration baseline to a collection, an assignment instance is created, populated with a minimum set of required values, and saved.
To assign Configuration Baselines
Set up a connection to the SMS Provider.
Create an instance of SMS_BaselineAssignment.
Populate the instance properties.
Save the new SMS_BaselineAssignment instance.
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
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.
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
The example method has the following parameters:
Parameter
Type
Description
connection
swbemServices
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
applyToSubTargets
Managed: Boolean
VBScript: Boolean
true to apply the configuration item assignment to a subcollection.
assignmentAction
Managed: Integer
VBScript: Integer
Action associated with the configuration item assignment.
assignmentName
Managed: String
VBScript: String
assignmentName
assignmentDescription
Managed: String
VBScript: String
The local assignment name.
desiredConfigType
Managed: String
VBScript: String
The type of the configuration item.
distributionPointLocality
Managed: Integer
VBScript: Integer
Flags that determine how the client obtains distribution points, according to distribution point locality.
evaluationSchedule
Managed: String
VBScript: String
The assignment evaluation schedule.
logComplianceToWinEvent
Managed: Boolean
VBScript: Boolean
true to log compliance status to Windows event logs.
notifyUser
Managed: Boolean
VBScript: Boolean
true to notify the user when a configuration item is available.
sendDetailedNonComplianceStatus
Managed: Boolean
VBScript: Boolean
true to send a detailed non-compliance status message.
startTime
Managed: String
VBScript: String
The date and time when the configuration item assignment was initially offered.
suppressReboot
Managed: Integer
VBScript: Integer
Value indicating whether the client should not reboot the computer, if there is a reboot pending after the configuration item is applied.
targetCollectionID
Managed: String
VBScript: String
The identifier of the collection to which the assignment is targeted.
useGMTTimes
Managed: Boolean
VBScript: Boolean
true if the times and schedules are in Universal Coordinated Time (UTC).
baselineID
Managed: Integer Array
VBScript: Integer Array
Array of IDs for the configuration items targeted by the assignment.