Udostępnij za pośrednictwem


PowerShell: Automating creation and editing of Task Sequences in 1706 (TP and CB)

Our development team has been working hard on implementing a much requested automation scenario for PowerShell in Configuration Manager, and that’s being able to create and modify task sequence steps.

Task sequence editing has three separate pieces: groups of steps, commands (such as “Install Application” and “Partition Disk”), and conditions. With 1706 Current Branch and Technical Preview we now have PowerShell support for creating and removing groups, all conditional statements, and what have been identified as the most commonly used task sequence steps.

The typical flow is something like this:

  1. Create your task sequence steps and groups (New-CMTaskSequenceStepCommand)
  2. Create a task sequence (New-CMTaskSequence)
  3. Add the steps you’ve created to the task sequence ($ts | Add-CMTaskSequenceStep –Step ($step1, $step2, $step3)

In 1706, the following Step types are supported for Get, New, Remove, and Set operations:

  • Run command line (Verb-CMTaskSequenceStepRunCommandLine)
  • Install application (Verb-CMTaskSequenceStepInstallApplication)
  • Install software (Verb-CMTaskSequenceStepInstallSoftware)
  • Install update (Verb-CMTaskSequenceStepInstallUpdate)
  • Partition disk (Verb-CMTaskSequenceStepPartitionDisk)
  • Reboot (Verb-CMTaskSequenceStepReboot)
  • Run PowerShell script (Verb-CMTaskSequenceStepRunPowerShellScript)
  • Setup Windows and Configuration Manager (Verb-CMTaskSequenceStepSetupWindowsAndConfigMgr)
  • Set variable (Verb-CMTaskSequenceStepSetVariable)

We plan to add additional Step types in future releases.

Here’s an example showing how easy it is to create a new custom task sequence that runs two PowerShell scripts:

 
$step1 = New-CMTaskSequenceStepRunPowerShellScript -Name "Run script 1" -PackageID $PackageId -ScriptName "script1.ps1" -ExecutionPolicy Bypass
$step2 = New-CMTaskSequenceStepRunPowerShellScript -Name "Run script 2" -PackageID $PackageId -ScriptName "script2.ps1" -ExecutionPolicy Bypass
$ts = New-CMTaskSequence -Name "Run scripts" -CustomTaskSequence
$ts | Add-CMTaskSequenceStep -Step ($step1, $step2)

If you’re interested in tracking the ongoing progress of this feature, you can follow the original feedback for this issue on UserVoice.