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

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:

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:dsc

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:runningTask.PNG

 

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

taskseq

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:cmtracepic

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.  

If you have any questions or just want to chat about Configuration Manager, OSD, PowerShell, DSC, GUIs, all that fun stuff, feel free to drop a line in the comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s