New-CMTSStepConditionIfStatement

Create an if statement condition for a task sequence step.

Syntax

New-CMTSStepConditionIfStatement
   [-Condition <IResultObject[]>]
   -StatementType <ConditionStatementType>
   [-DisableWildcardHandling]
   [-ForceWildcardHandling]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

Use this cmdlet to create an if statement condition object for a task sequence step. Then use one of the New-CMTSStep* or Set-CMTSStep* cmdlets with the Condition or AddCondition parameters. For example, Set-CMTSStepApplyDataImage.

For more information, see Use the task sequence editor: Conditions.

Note

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

Examples

Example 1

This example first uses the New-CMTSStepConditionFile and New-CMTSStepConditionQueryWMI cmdlets to create child condition objects. It passes those two objects to the New-CMTSStepConditionIfStatement cmdlet and saves that condition object.

It then uses the Set-CMTSStepSetDynamicVariable cmdlet to add this condition object to the Set Dynamic Variables step of the Default OS deployment task sequence.

$file = "C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\en-US\AdminUI.PS.dll-Help.xml"
$datetime = Get-Date ("August 2, 2021")
$conditionFile = New-CMTSStepConditionFile -FilePath $file -FileTimestamp $datetime -FileDateTimeOperator Greater

$model = "Latitude E7470"
$wmiQuery = "Select * From Win32_ComputerSystem Where Model = `"$Model`""
$conditionQuery = New-CMTSStepConditionQueryWMI -Namespace "root\cimv2" -Query $wmiQuery

$condition = New-CMTSStepConditionIfStatement -StatementType All -Condition $conditionFile,$conditionQuery

$tsNameOsd = "Default OS deployment"
$tsStepNameSetDynVar = "Set Dynamic Variables"

Set-CMTSStepSetDynamicVariable -TaskSequenceName $tsNameOsd -StepName $tsStepNameSetDynVar -AddCondition $condition

If  All  the conditions are true:
    File  C:\Program Files (x86)\Microsoft Endpoint Manager\AdminConsole\bin\en-US\AdminUI.PS.dll-Help.xml exists  and  timestamp greater than "8/1/2021 16:00:00"
    WMI Query  Select * From Win32_ComputerSystem Where Model = "Latitude E7470"

Parameters

-Condition

Specify one or more condition objects to include in this if statement block. To get these nested objects, use one of the New-CMTSStepCondition* cmdlets. For example, New-CMTSStepConditionFile.

Type:IResultObject[]
Aliases:SubCondition, SubConditions
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

-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

-StatementType

Specify the type of if statement to create. There are three types of checks that you can do with this condition:

  • If All of the conditions are true
  • If Any of the conditions are true
  • If None of the conditions are true
Type:ConditionStatementType
Aliases:Operator
Accepted values:All, Any, None
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

Notes

For more information on this return object and its properties, see SMS_TaskSequence_ConditionOperator server WMI class.