Hello, and Happy Christmas!
So I was discussing this recently, and I thought “Wouldn’t it be better if task sequence steps had some form of naming convention”.  Perhaps the same way you might have for machines, GPO’s or Intune policies.  I started to look into it thinking “oh that will be easy” it’ll only be something like “Set-CMTaskSequenceStep -Name ‘NewName'”, yeah this will be a ‘walk in the park’.
It wasn’t.
I threw a command to investigate cmdlets available first.
[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
Get-Command -Module ConfigurationManager *CMTask*
[/css]

Now, I see “Remove-CMTaskSequenceStep”, “Get-CMTaskSequenceStep”, “Add-CMTaskSequenceStep”…but no “Set-CMTaskSequenceStep”.  Strange.
Lets see if there’s anything I’ve missed anything here.
[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
Get-Command *CMTask*
[/css]
WOAH! Lots of commands, looks like there’s another module called “AdminUI.PS.Osd“…. Sweet!
Lets narrow down what we’ve got.
[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
Get-Command -Module AdminUI.PS.Osd *Set-CMTaskSequenceStep*
[/css]

CRAP!  Looks like there’s a Set command for each type of task sequence step.   Adding a count on shows 34 Set commands, so at least for now, we can cover 34 different types of Task Sequence Step.
So problems I now see are, I’m going to have to find out each of the types and tie them to specific commands *insert crying face*
OK, lets make a start….
I’m going to need to investigate what task sequence steps I have and I can see that one of the properties of each step available to me is “SmsProviderObjectPath”, which is the property that identifies the type of step in question.  So I will pipe the variable to a “Format-Table” command and investigate the name and type of the task sequence steps I have in my sequence.
Before I did that though, its clear which one I am going to be able to manipulate based upon the Set commands available to me so I quickly knock up a task sequence with 34 steps of different types, setting them to disabled because it doesn’t matter to me, I’m just going to look to change the name.

Sweet! So lets try to rename these bad boys!
[Mental Note – Take a copy of the “Master” and play with that so that you can delete and re-create if you make mistakes!]
Next bit of code I’m going to throw has three steps.

  1. Specify the Task Sequence Package ID Number in a variable
  2. Put the Task Sequence steps into a variable
  3. Output that variable to a table, and only specify the step name and the SmsProviderObjectPath we discovered earlier.

[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
$TaskSequenceID = "P0100001"
$TSSteps = (Get-CMTaskSequenceStep -TaskSequenceId $TaskSequenceID)
$TSSteps | Format-Table Name, SmsProviderObjectPath
[/css]

Ok, next up is I’m going to find out how to get the lockstate of a task sequence, because if I try to edit something that’s locked its going to have a fit.  Because I’m looking at the task sequence object this time I’m going to pass that into a variable and in turn pass that to the cmd “Get-CMObjectLockState”.  I did spend some time looking at the properties of the Task Sequence object, assuming there would be a “LockState” property but there wasn’t, instead you put the task sequence object into a variable and pass it as an input object to find out.  Like so..
[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
$TaskSequenceID = "P0100001"
$TS = (Get-CMTaskSequence -TaskSequencePackageId $TaskSequenceID)
$LockState = Get-CMObjectLockDetails -InputObject $TS
[/css]

The LockState property highlighted is what I’m interested in.

  • 0 = Open
  • 1 = Locked

Sweet.
So next up is to examine the Set commands I highlighted above, the ones that tie to the 34 Task Sequence step types.  I’ll save you some time here by just doing one but I spent time examining a few and noticed they all have some common a parameters such as “-StepName” and “-NewStepName”.

I tested with “-StepName” for a while, wasn’t right.  “-NewStepName” is what you want.
Got that working.
So what now?  Logic would point towards something along the lines of “If task sequence step of a certain type, use a certain cmdlet to change the name“.
So first I spent a considerable amount of time mapping the “Set-” cmdlets to the “SmsProviderObjectPath” property.  Correcting a few typos and such and had them working just fine.  I wrapped all that up with two clauses “If we can find the configuration manager module” (because otherwise we cant proceed) and “if task sequence is not locked”, go get the task sequence and all the steps.  Check each step and if it matches on the list (via SmsProviderObjectPath property) the use the corresponding cmdlet to update the step name.
Wrap that up with some parameters “TaskSequenceID”, “SiteServer” and “SiteCode”.  Sprinkle on some ninja stars and use a Switch statement (because the If Else took foreeeeeeeever).  With a dollop of write-output and VOILA!
My Task Sequence step renaming tool.
[css autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true”]
<#
.Synopsis
Task Sequence Step Renamer
.AUTHOR
Jonathan Fallis – www.deploymentshare.com
Twitter (Blog) – @deploymentshare
Twitter (personal) – @jonniehack
Please Follow!
.DESCRIPTION
This will rename task sequence steps by giving them a prefix. Currently, 34 types of step are supported so not all are available as there are only so many task sequecne cmdlets
.EXAMPLE
The following example set all properties during install
Rename-TaskSequenceSteps -TaskSequenceID "P010000A" -SiteCode "PS1" – SiteServer "server.subdomain.domain.local"
.EXAMPLE
The following example relies on the correct sitecode and site server being set in the script itself
Rename-TaskSequenceSteps -TaskSequenceID "P010000A"
.EXAMPLE
The following example relies on the correct sitecode and site server being set in the script itself, it also outputs verbose messages
Rename-TaskSequenceSteps -TaskSequenceID "P010000A" -Verbose
#>
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Task Sequence ID
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$TaskSequenceID,
# SiteCode
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$false,
Position=1)]
$SiteCode = "P01",
# SiteServer
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$false,
Position=2)]
$SiteServer = "pdms01ps1"
) # Param
If (!(Get-Module -Name ConfigurationManager -ErrorAction SilentlyContinue)) {
Try {
# Customizations
$initParams = @{}
#$initParams.Add("Verbose", $true) # Uncomment this line to enable verbose logging
#$initParams.Add("ErrorAction", "Stop") # Uncomment this line to stop the script on any errors
# Site configuration
$ProviderMachineName = $SiteServer # SMS Provider machine name
# Import the ConfigurationManager.psd1 module – Error action makes it a terminating error, so the catch will catch it
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams -ErrorAction Stop
# Connect to the site’s drive if it is not already present
if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams
}
Set-Location "$($SiteCode):\"
} # Try
Catch {
Write-Warning "Cannot find ConfigMgr Module, sorry – Go fix it"
Set-Location C:
Break
} # Catch
} # If ConfigMgr Module
#Get Task Sequence
$TS = (Get-CMTaskSequence -TaskSequencePackageId $TaskSequenceID)
#Get All Task Sequence Steps
$TSSteps = (Get-CMTaskSequenceStep -TaskSequenceId $TaskSequenceID)
#Lockstate of Task Sequence
$LockState = (Get-CMObjectLockDetails -InputObject $TS).Lockstate
Write-Verbose "LockState of $($TS.Name) is $LockState"
If ($LockState = "0") {
foreach ($Step in $TSSteps)
{
$StepType = $Step.SmsProviderObjectPath
$Name = $Step.Name
Write-Output "Processing: $($Name)"
Switch ( $StepType )
{
SMS_TaskSequence_ApplyDataImageAction {$Prefix = "ADI: "; If ($Step.Name -notmatch "$($Prefix)"){Set-CMTaskSequenceStepApplyDataImage -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ApplyDriverPackageAction {$Prefix = "DRVPKG: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepApplyDriverPackage -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ApplyNetworkSettingsAction {$Prefix = "NET: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepApplyNetworkSetting -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ApplyOperatingSystemAction {$Prefix = "OS: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepApplyOperatingSystem -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ApplyWindowsSettingsAction {$Prefix = "WIN: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepApplyWindowsSetting -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_AutoApplyAction {$Prefix = "AADRV: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepAutoApplyDriver -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_CaptureNetworkSettingsAction {$Prefix = "CAP-NWK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepCaptureNetworkSettings -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_CaptureSystemImageAction {$Prefix = "CAP-IMG: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTSStepCaptureSystemImage -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_CaptureUserStateAction {$Prefix = "CAP-USR: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepCaptureUserState -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_CaptureWindowsSettingsAction {$Prefix = "CAP-WIN-SET: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepCaptureWindowsSettings -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ConnectNetworkFolderAction {$Prefix = "NWK-FLD: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepConnectNetworkFolder -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ConvertDiskAction {$Prefix = "CON-DISK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepConvertDisk -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_DisableBitLockerAction {$Prefix = "D-BLK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepDisableBitLocker -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_DownloadPackageContentAction {$Prefix = "PKGC: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepDownloadPackageContent -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_EnableBitLockerAction {$Prefix = "E-BLK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepEnableBitLocker -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_InstallApplicationAction {$Prefix = "APP: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepInstallApplication -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_InstallSoftwareAction {$Prefix = "PKG: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepInstallSoftware -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_InstallUpdateAction {$Prefix = "UPDATE: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepInstallUpdate -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_JoinDomainWorkgroupAction {$Prefix = "DOMAIN: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepJoinDomainWorkgroup -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_OfflineEnableBitLockerAction {$Prefix = "O-BLK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepOfflineEnableBitLocker -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_PartitionDiskAction {$Prefix = "DISK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepPartitionDisk -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"} }
SMS_TaskSequence_PrepareSMSClientAction {$Prefix = "PREPSMS: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepPrepareConfigMgrClient -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_PrepareOSAction {$Prefix = "PREPSMS: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepPrepareWindows -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_PrestartCheckAction {$Prefix = "CHECK: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepPrestartCheck -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_RebootAction {$Prefix = "REBOOT: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepReboot -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_ReleaseStateStoreAction {$Prefix = "REL-USMT: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepReleaseStateStore -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_RequestStateStoreAction {$Prefix = "REQ-USMT: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepRequestStateStore -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_RestoreUserStateAction {$Prefix = "RES-USMT: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepRestoreUserState -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_RunCommandLineAction {$Prefix = "CMD: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepRunCommandLine -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_RunPowerShellScriptAction {$Prefix = "PoSH: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepRunPowerShellScript -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_SetDynamicVariablesAction {$Prefix = "DVAR: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepSetDynamicVariable -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_SetupWindowsAndSMSAction {$Prefix = "SMS: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepSetupWindowsAndConfigMgr -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_SetVariableAction {$Prefix = "VAR: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepSetVariable -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
SMS_TaskSequence_UpgradeOperatingSystemAction {$Prefix = "UPGRADE-OS: "; If ($Step.Name -notmatch "$($Prefix)") {Set-CMTaskSequenceStepUpgradeOperatingSystem -InputObject $TS -NewStepName "$($Prefix) $($Name)"; Write-Warning "–Changed to: ‘$($Prefix) $($Name)’"} Else {Write-Warning "No Change Required"}}
} #Close Switch
} # Close foreach
} #If Lockstate
Else {
Write-Warning "Cannot make changes – Your task sequence is open and therefore – locked, sorry – Go fix it"
Set-Location C:
Break
}# Else Lockstate
[/css]
I even did a nice output for you 🙂

It will take your task sequence steps and rename them like so, with a prefix…

I set the prefix variable to be the first variable set in the switch statement options (because I’m just that nice) so that you can change the prefixes to anything you want with ease
A step forward in standardising stuff. The amount of Task Sequences I’ve cracked open and time I’ve wasted investigating things. I think this could be really useful.
Thanks for reading
Jonathan
Download The Script Here:    Rename-TaskSequenceSteps