Conditions can be added to an operating system deployment step (action and group), in System Center 2012 Configuration Manager, by creating a SMS_TaskSequence_Condition class instance and then associating it with the step. If the condition operands are all met, then the step is processed; otherwise it is not. The condition can have one or more operands that are instances of SMS_TaskSequence_Condition derived classes. You specify operators for the operands with instances of SMS_TaskSequence_ConditionOperator.
![]() |
---|
System Center 2012 Configuration Manager provides several classes that provide useful expressions such as Windows Management Instrumentation (WMI) queries and file operations. For more information, see Operating System Deployment Server WMI Classes. |
To add a condition to a step
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Obtain a task sequence step object. This can be an SMS_TaskSequence_Group object for a group, or a SMS_TaskSequenceAction derived class object for an action, for more information, see How to Add an Operating System Deployment Task Sequence Action.
-
Create a new condition by creating an instance of SMS_TaskSequence_Condition.
-
Create an expression for the condition by creating an instance of an SMS_TaskSequence_ConditionExpression derived class. For example, SMS_TaskSequence_RegistryConditionExpression.
-
Populate the expression properties.
-
Add the expression to the condition Operands property.
-
Add the condition to the task sequence step class Condition property.
Example
The following example method adds a condition to a supplied step that determines if the HKEY_LOCAL_MACHINE\MICROSOFT registry key exists. The SMS_TaskSequenc_RegistryCondition Expression is used to specify the condition.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | ![]() |
---|---|
Sub AddRegistryCondition (connection, taskSequenceStep) Dim condition Dim registryExpression Dim operands ' Get or create the condition. if IsNull ( taskSequenceStep.Condition) Then Set condition = connection.Get("SMS_TaskSequence_Condition").SpawnInstance_ Else Set condition = taskSequenceStep.Condition End If ' Populate the condition. Set registryExpression=connection.Get("SMS_TaskSequence_RegistryConditionExpression").SpawnInstance_ registryExpression.KeyPath="HKEY_LOCAL_MACHINE\MICROSOFT" registryExpression.Operator="exists" registryExpression.Type="REG_SZ" registryExpression.Data=Null ' Add the condition. operands=Array(registryExpression) condition.Operands=operands taskSequenceStep.Condition=condition End Sub |
C# | ![]() |
---|---|
public void AddRegistryCondition( WqlConnectionManager connection, IResultObject taskSequenceStep) { try { IResultObject condition; if (taskSequenceStep["Condition"].ObjectValue == null) { // Create a new condition. condition = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_Condition"); } else { // Get the existing condition. condition = taskSequenceStep.GetSingleItem("Condition"); } // Create and populate the expression. IResultObject registryExpression = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_RegistryConditionExpression"); registryExpression["KeyPath"].StringValue = @"HKEY_LOCAL_MACHINE\MICROSOFT"; registryExpression["Operator"].StringValue = "exists"; registryExpression["Type"].StringValue = "REG_SZ"; registryExpression["Data"].StringValue = null; // Get the operands and add the expression. List<IResultObject> operands = condition.GetArrayItems("Operands"); operands.Add(registryExpression); // Add the expresssion to the list of operands. condition.SetArrayItems("Operands", operands); // Add the condition to the sequence. taskSequenceStep.SetSingleItem("Condition", condition); } catch (SmsException e) { Console.WriteLine("Failed to create Task Sequence: " + e.Message); throw; } } |
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection |
|
A valid connection to the SMS Provider. |
taskSequenceStep |
|
A valid task sequence step (SMS_TaskSequenceStep). |
Compiling the Code
The C# example has the following compilation requirements:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
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 Add an Operating System Deployment Task Sequence ActionHow 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
Concepts
Configuration Manager Operating System DeploymentConfiguration Manager Objects
Configuration Manager Programming Fundamentals
Operating System Deployment Task Sequencing