Edit

Share via


New-CMTSStepConditionIfStatement

Create an if statement condition for a task sequence step.

Syntax

Default (Default)

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.

Parameter properties

Type:

IResultObject[]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:SubCondition, SubConditions

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DisableWildcardHandling

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ForceWildcardHandling

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments: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

Parameter properties

Type:ConditionStatementType
Default value:None
Accepted values:All, Any, None
Supports wildcards:False
DontShow:False
Aliases:Operator

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

None

Outputs

IResultObject

Notes

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