New-CMTSRule

Create a rule to add to a Set Dynamic Variables task sequence step.

Syntax

New-CMTSRule
   -Variable <Hashtable>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-CMTSRule
   [-AssetTag <String>]
   [-MacAddress <String>]
   [-SerialNumber <String>]
   [-Uuid <String>]
   -Variable <Hashtable>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-CMTSRule
   [-DefaultGateway <String>]
   -Variable <Hashtable>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-CMTSRule
   [-Make <String>]
   [-Model <String>]
   -Variable <Hashtable>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-CMTSRule
   [-ReferencedVariableName <String>]
   [-ReferencedVariableOperator <VariableOperatorType>]
   [-ReferencedVariableValue <String>]
   -Variable <Hashtable>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

Use this cmdlet to create a rule object that you add to a Set Dynamic Variables task sequence step. To add rules, use the New-CMTSStepSetDynamicVariable or Set-CMTSStepSetDynamicVariable cmdlets. When the task sequence runs this step, it evaluates the dynamic rules and variables in order. When it evaluates the rules on the specific device, it can then set task sequence variables based on those rules.

There are four types of rules:

  • Computer: Evaluate values for hardware asset tag, UUID, serial number, or MAC address.
  • Location: Evaluate values for the default network gateway.
  • Make and Model: Evaluate values for the make and model of a computer.
  • Task sequence variable: Add a task sequence variable, condition, and value to evaluate.

For more information, see Dynamic rules and variables.

Note

Run Configuration Manager cmdlets from the Configuration Manager site drive, for example PS XYZ:\>. For more information, see getting started.

Examples

Example 1: Set the download destination if in Windows PE

This example creates the following rule:

IF _SMSTSInWinPE equals "TRUE" THEN SET OSDDownloadDestinationLocationType = "TSCache"

It then adds this rule to an existing instance of this step in a task sequence.

$tsrule = New-CMTSRule -Variable @{'OSDDownloadDestinationLocationType' = 'TSCache'} -ReferencedVariableName "_SMSTSInWinPE" -ReferencedVariableOperator equals -ReferencedVariableValue TRUE

$tsname = "Default IPU"
$tsstep = "Set Dynamic Variables"

Set-CMTSStepSetDynamicVariable -TaskSequenceName $tsname -StepName $tsstep -AddRule $tsrule

Parameters

-AssetTag

Specify an Asset tag for the Computer rule type. The maximum value is 255 characters.

For example, if you set this value to 123456, it adds the following rule: IF Asset tag equals "123456" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultGateway

Specify the Default gateway for the Location rule type.

For example, if you set this value to 192.168.10.1, it adds the following rule: IF Default gateway equals "192.168.10.1" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DisableWildcardHandling

This parameter treats wildcard characters as literal character values. You can't combine it with ForceWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ForceWildcardHandling

This parameter processes wildcard characters and may lead to unexpected behavior (not recommended). You can't combine it with DisableWildcardHandling.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MacAddress

Specify the MAC address for the Computer rule type.

For example, if you set this value to 00:11:22:33:44:55, it adds the following rule: IF MAC address equals "00:11:22:33:44:55" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Make

Specify the Make for the Make and Model rule type. To set the other value, use the Model parameter. The rule evaluates true when both values are true.

You can use wildcard characters:

  • *: Multiple characters
  • ?: Single character

For example, if you set this value to Surface and the Model to *, it adds the following rule: IF Make equals "Surface" AND Model equals "*" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Model

Specify the Model for the Make and Model rule type. To set the other value, use the Make parameter. The rule evaluates true when both values are true.

You can use wildcard characters:

  • *: Multiple characters
  • ?: Single character

For example, if you set this value to * and the Make to Surface, it adds the following rule: IF Make equals "Surface" AND Model equals "*" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ReferencedVariableName

Specify the Variable for the Task Sequence Variable rule type. It requires that you also set the ReferencedVariableOperator and ReferencedVariableValue parameters.

This variable name can be a built-in task sequence variable or a custom one that you created. For more information, see How to use task sequence variables in Configuration Manager.

For example, if you set the following values:

  • ReferencedVariableName: OSDRegisteredOrgName
  • ReferencedVariableOperator: Equals
  • ReferencedVariableValue: Contoso

Then it adds the following rule: IF OSDRegisteredOrgName equals "Contoso" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ReferencedVariableOperator

Specify the Condition for the Task Sequence Variable rule type. It requires that you also set the ReferencedVariableName and ReferencedVariableValue parameters. For the available operators, see the list of accepted values for this parameter.

For example, if you set the following values:

  • ReferencedVariableName: OSDRegisteredOrgName
  • ReferencedVariableOperator: Equals
  • ReferencedVariableValue: Contoso

Then it adds the following rule: IF OSDRegisteredOrgName equals "Contoso" THEN

Type:VariableOperatorType
Accepted values:Exists, NotExists, Equals, NotEquals, Greater, GreaterEqual, Less, LessEqual, Like, NotLike
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ReferencedVariableValue

Specify the Value for the Task Sequence Variable rule type. It requires that you also set the ReferencedVariableName and ReferencedVariableOperator parameters.

For example, if you set the following values:

  • ReferencedVariableName: OSDRegisteredOrgName
  • ReferencedVariableOperator: Equals
  • ReferencedVariableValue: Contoso

Then it adds the following rule: IF OSDRegisteredOrgName equals "Contoso" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SerialNumber

Specify a Serial number for the Computer rule type.

For example, if you set this value to 123456, it adds the following rule: IF Asset tag equals "123456" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Uuid

Specify a UUID for the Computer rule type.

For example, if you set this value to de5ba380-f692-45e0-bbd3-0e40543b549e, it adds the following rule: IF UUID equals "de5ba380-f692-45e0-bbd3-0e40543b549e" THEN

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Variable

Specify the existing or custom task sequence variables and associated values that the step should set when the rule evaluates to true.

For example, if you set this value to @{'OSDDownloadDestinationLocationType' = 'TSCache'}, it adds the following variable after the THEN of the rule: SET OSDDownloadDestinationLocationType = "TSCache"

To specify more than one variable in the same hashtable, use a semi-colon (;) delimiter. For example: @{'OSDRegisteredUserName' = 'Contoso';'OSDRegisteredOrgName' = 'Contoso'}

Type:Hashtable
Aliases:Variables
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet doesn't run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

IResultObject