***Updated 7/11/19*** Changed numbering to include Start and end number for groups and sub task sequences.
On several occasions at the local user group and at MMS, I have heard the discussion about wanting to have numbers in the task sequence steps that corresponds to the execution steps reported in the smsts.log file and those reported back to the ConfigMgr database (these are both the same numbering of course). There is also a user voice that exists for this very item and has been there for quite some time.
So, on Monday night of MMS this year, I was thinking about something to demo at the Tips and Tricks Showcase on Wednesday. I wanted to do something that was kind of cool, and I thought of this. Well, I didn't get it done by Wednesday night.
Initially, this seems like a simple enough problem to solve. Almost anyone can count (even me) :-). And even most of us can count past 10 or 20 (fingers and toes). But, that would be too easy. (At any point, feel free to fast forward down to the Installing and using the Console Extension section of this post to get to the tool)
Why do I say it is too easy? First, lets take a step back and answer the question of "Why do I want step numbers in the console for a Task Sequence". Well, if the task sequence says it failed on step 124, or you have someone say it failed on step "Reboot Computer" (chances are you have a few of these), it just isn't terribly accurate. you want to be able to see step 124 and "Reboot computer" in the same line so you can easily correlate in the editor, where the failure is (remember, no numbering in the editor, only names).
So, why hasn't this been done and why isn't it easy? Well, because task sequences are not easy (well complex ones aren't). There is more to what is going on with this numbering process than meets the eye. So, lets take a look at how things get numbers.
We can start by taking a look at the types of objects that can be in a task sequence. Fortunately, there are currently only 3 types of items that exist that we need to worry about for numbering: Steps, Groups, and Sub Task Sequences. Lets take a closer look at each.
Steps are pretty simple and straight forward when it comes to numbering. When a step is executed, it counts as one in a task sequence for logging. Doesn't matter the the type of step, script execution, install OS, install Application, run package. All of these are 1 in and same 1 out. Also doesn't matter if they are enabled or not, they still count in the steps. Or if they don't run because of conditions. Always one step.
Groups are a little more complex than a step. A group, when looking at a task sequence is just a folder of steps. This allows you to organize and also build conditions for a bunch of related steps. Groups are different than a step in one specific way. They are 1 in and 2 out. So, when logging, it counts a step for starting to execute a group and then counts a second step for completing the execution of a group. Groups also don't matter if they are disabled or not. Always 2 steps counted in the sequence. Same for if they don't run the group because of a condition.
Sub Task Sequence
A Sub Task Sequence (STS) is the most complex of all of these. Like a group, a STS counts 1 in and 2 out. But, it also counts all of the steps in the Task Sequence that is called, following the normal rules. On top of this, I have found that if you disable a STS step, or its parent group then, its steps are not counted at all! So, this is where the whole thing gets complicated. Up until now, you just counted everything as a step. But, for whatever reason, STS's behave differently when it comes to logging and status messages. So, this took some additional work to figure out and account for. Fortunately, if the step is enabled with conditions and the conditions evaluate to false, it will still count all the steps. Oofta. If that wasn't the case, I probably would have thrown in the towel and said, this is not going to happen.
Let's Number a Task Sequence
So, with this in mind, lets look at a task sequence and see how it would be numbered. I have a short task sequence with about 20 steps. This TS includes groups and a nested task sequence. So, the numbering would look like this:
Pretty straight forward numbering there. Now, if I look at what is recorded for an execution of this task sequence in the CM database, we'll see the following with this query:
SELECT [ExecutionTime] ,[Step] ,[GroupName] ,[ActionName] ,[ExitCode] ,[LastStatusMsgName] FROM [vSMS_TaskSequenceExecutionStatus] where PackageID = 'MMS00019' order by ExecutionTime desc
Now, let's disable the Doing Stuff group and see how the numbering changes. Rememeber, since the sub task sequence is part of the disabled group, it is also disabled so, it isn't counted in the steps.
And then, when you look at an execution in SQL, you will see these results.
Now, that I knew how the numbering changes throughout, I could write a script to make the changes. This ended up being a adventure with recursion in PowerShell that I won't get into right now. But, I basically needed to recurse my way through the XML (because a task sequence is just a big pile of xml) and change all the the names along the way, prepending the step number. The resulting script is out on my GitHub repo here (Set-TSStepNumbers.ps1).
My next logical step was to build a console extension for this; something I had never done before. Luckily, the Ephing Admin has an excellent tutorial for doing this. So, following that tutorial, and then borrowing and modifying the Invoke-ToolInstallation.ps1 from Nickolaj Andersen here to use as my install script for my extension.
So, once the extesion was built and installed, I was numbering task sequences from the console.
Installing and using the Console Extension
Now that I've bored you to death with my story, lets get to installing the console extension so you can start numbering your task sequences as well.
- Download the zip file attached here, or get the latest from the GitHub repository.
- Expand the zip file.
- Open an elevated PowerShell window and browse to the expanded zip file.
- Run the following command on a computer with the SCCM:
.\Invoke-ToolInstallation.ps1 -SiteServer CM01.domain.com -Method Install -Path C:\Scripts -Verbose
- If you (and I) did everything correct, you should now have the console extension you see in the picture above. and should be able to do the following with your TS.
Ok... Well, next time I'll lead with this. :)
That's it. Seems to be pretty accurate too. I don't do a ton of work with nested task sequences so, I have not tested a lot against them. But, the basic mechanics seem to be here and should work for everything else. Of course, all my testing was against CB 1810 and 1902. But should work with earlier versions.
Have Fun! Let me know how it works.
With the update on 7/11/19, you will now have the start and end number on a group or sub task sequence step. So, our sample TS from above will look like this now:
Thanks for sharing TS steps console extension. Will come handy during next testing at home lab. Will definitely recommend this at work for PROD use as well.