Creating Task Sequences in ConfigMgr via PowerShell

ConfigMgr 1710 has even more PowerShell cmdlets for creating and editing task sequences compared to ConfigMgr 1706. 34 more to be exact, growing them from 75 to 109 (including alias names because I was lazy 🙂 ).

Tip: You might also want to check out some of the PowerShell samples from Ari Saastamoinen (@AriSaastamoinen) on his blog:  http://arisaastamoinencom.blogspot.fi/2017/08/sccm-ts-with-powershell.html

Sample

Here is a short sample to create a new custom task sequence with two groups, and two run command line actions:

# Create a new Task Sequence
$TS = New-CMTaskSequence -CustomTaskSequence -Name "Create TS Via PowerShell"

# Create the first group
$Group1 = New-CMTaskSequenceGroup -Name "First Group"
Add-CMTaskSequenceStep -InsertStepStartIndex 0 -TaskSequenceName $TS.Name -Step $Group1

# Create the first Run Command Line action
$Step1 = New-CMTaskSequenceStepRunCommandLine -StepName "Run Command 1" -CommandLine "cmd.exe /c"
Set-CMTaskSequenceGroup -TaskSequenceName $TS.Name -StepName $Group1.Name -AddStep $Step1 -InsertStepStartIndex 0

# Create the second group
$Group2 = New-CMTaskSequenceGroup -Name "Second Group"
Add-CMTaskSequenceStep -InsertStepStartIndex 1 -TaskSequenceName $TS.Name -Step $Group2

# Create the second Run Command Line action
$Step2 = New-CMTaskSequenceStepRunCommandLine -StepName "Run Command 2" -CommandLine "cmd.exe /c"
Set-CMTaskSequenceGroup -TaskSequenceName $TS.Name -StepName $Group2.Name -AddStep $Step2 -InsertStepStartIndex 0

Result

Yep, here it is.

image
The resulting task sequence.

Written by Johan Arwidmark

About the author

Johan Arwidmark

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

>