In System Center 2012 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.
Visual Basic Script | Copy Code |
---|---|
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 |
C# | Copy Code |
---|---|
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."); } |
The example method has the following parameters:
Parameter |
Type |
Description |
|
|
A valid connection to the SMS Provider. |
applyToSubTargets |
|
true to apply the configuration item assignment to a subcollection. |
assignmentAction |
|
Action associated with the configuration item assignment. |
assignmentName |
|
assignmentName |
assignmentDescription |
|
The local assignment name. |
desiredConfigType |
|
The type of the configuration item. |
distributionPointLocality |
|
Flags that determine how the client obtains distribution points, according to distribution point locality. |
evaluationSchedule |
|
The assignment evaluation schedule. |
logComplianceToWinEvent |
|
true to log compliance status to Windows event logs. |
notifyUser |
|
true to notify the user when a configuration item is available. |
sendDetailedNonComplianceStatus |
|
true to send a detailed non-compliance status message. |
startTime |
|
The date and time when the configuration item assignment was initially offered. |
suppressReboot |
|
Value indicating whether the client should not reboot the computer, if there is a reboot pending after the configuration item is applied. |
targetCollectionID |
|
The identifier of the collection to which the assignment is targeted. |
useGMTTimes |
|
true if the times and schedules are in Universal Coordinated Time (UTC). |
baselineID |
|
Array of IDs for the configuration items targeted by the 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
Tasks
How to Connect to an SMS Provider in Configuration Manager by Using Managed CodeHow to Connect to an SMS Provider in Configuration Manager by Using WMI
Reference
SMS_BaselineAssignment Server WMI ClassConcepts
About Configuration Baselines and Configuration ItemsHow to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code