ITS Partners Insights

Troubleshooting PowerShell DSC in a Configuration Manager Task Sequence using ServiceUI.exe and CMTrace.exe

Written by Chad Dupin | January 19, 2017

These past couple months I have been playing around with a lot of PowerShell.

Particulary in the form of GUIs and Desired State Configuration (DSC).  Today I am here to talk about a nifty little utility that is part of the Microsoft Deployment Toolkit called ServiceUI.exe.

If you have ever tried to launch an HTA or a custom “front end” in a Configuration Manager task sequence, then you might be familiar with ServiceUI.exe.  ServiceUI.exe is the same utility the Microsoft folks use to initiate the UDI wizard in MDT.  Here is a link from the MDT 2010 days that explain where ServiceUI comes from as well as how to use it to launch an EXE interactively, as well as an HTA during a Configuration Manager or MDT task sequence.  There are plenty of great articles out there that explain how to use ServiceUI for launching an interactive prompt, so we’re not going to talk about that,  exactly.

I mentioned I have been learning PowerShell Desired State Configuration or DSC. Absolutely amazing!  I have been working on a fairly simple project, and I am using Configuration Manager to build a server, and install some Windows Roles and Features using powershell DSC.  Pretty basic stuff all said and done.

Here is an example of some of the powershell used to install the roles:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Configuration NewServer
{
param (
[ Parameter ( Mandatory = $true )]
[String[]] $Server
)
Node $Server
{
$SERVERROLES = "FS-FileServer" , "RDC" , "Web-WebServer"
Foreach ( $i in $SERVERROLES )
{
WindowsFeature "$i"
{
Name = "$i"
Ensure = "Present"
LogPath = "C:\prereg.log"
}
}
}
}

Some of these servers have up to 20 or more roles and features that need to be installed prior to setting them up.  I have learned that this process can take upwards of over an hour to complete.  Add DSC into the mix and it’s going to increase the time as well by the very nature of what DSC does.  (See here for more information on PowerShell  DSC.)

So how did I use all of this for troubleshooting?  As many of us know, Configuration Manager runs its tasks under the System context, meaning when we run a script or command we do not actually see the process.  We cannot interact with it.  Well when my task would get to the point where it was running the PowerShell script to install the roles, it seemed like it was just doing nothing for a very long time, and we all know how frustrating that can be.  Looking at Task Manager showed that it was responsive.  CPU was fluxuating, and memory utilization was as well.  “But what was it doing?!?”

Here is an example of the PowerShell DSC output from a Windows Role install:

Here we can see exactly what role it is working on.  With PowerShell DSC, simply being able to see the output on the screen can be helpful and informative.  We can see if it is in the test or set phase, and we can see how long it took to install the role.  (In this example the roles were already installed, so the steps completed in anywhere from 20 – 30 seconds each.)

Next we will see what the step actually looks like running it in an OSD task sequence.

Below is a screenshot of the task running:

Here is the actual command line that will run this task:

I simply took the ServiceUI.exe file from the MDT install directory (C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution\Tools\x64), added it to a package, and call it from that package.

You may have also noticed a line in the code above defining a logpath.  We certainly do have logging capabilities, and using CMTrace.exe (the Microsoft Configuration Manager log viewer) to view the log, I can monitor it real time. But I think there is something to be said about simply seeing the screen output that puts our minds at ease. (Or maybe it’s just my OCD.)

Here is an example of the log output from the DSC script:

There we have it.  2 methods for troubleshooting PowerShell DSC scripts during a Configuration Manager task sequence.

So what exactly was my task doing all that time?  Just taking its sweet time is all.

About the Author

Adam Eaddy Adam is a consultant with ITS Partners, with a focus primarily on Configuration Manager, Intune, Azure and Office 365. He specializes in Computer Imaging, focusing on customizing Windows look and feel and designing deployment methodologies. Check out his personal blog at adameaddy.wordpress.com.