Checking SCCM Task Sequence Variables using Powershell

While running an OSD task sequence you can use powershell to check the TS Environment variables.

I added a ‘Pause’ step using this guide.┬áIf, like me, you are using an x64 PE image, you need use the ‘serviceui.exe’ from either the Program Files location on the machine with MDT installed, or a MDT package :


Once you have your Task Sequence paused, you can press F8 (if enabled in the boot image) and start powershell.

$env = New-Object -COMObject Microsoft.SMS.TSEnvironment

This will create an interface to the com object we need to use to interact with the TS environment.

$env.GetVariables() | % {$_ + "=" + $env.Value($_)}

This will dump out all the variables to the screen, this is a bit messy as there are lots of variables – some with quite long xml text as the values.

This will output all the variables to a text file :

$env.GetVariables() | % {$_ + "=" + $env.Value($_)} | out-file "variables.txt"

This will display the value of a specific variable (e.g. Architecture):


You could adapt this into a script to run automatically, instead of manually if required.


How to Reduce winsxs Folder Size on Windows 7

Recently I had an issue with a Windows 7 deployment, the winsxs folder was very large. I wasn’t able to look into whether this was a problem with our wim, or the updates process. But this is how I gained 7GB of space back…

This is how much space Windows folder was taking up before the cleanup process :

Size of Windows Folder before cleanup
Size of Windows Folder before cleanup shown using Treesize Free

Install this patch :


Run Disk Cleanup as Admin.


Ensure that “Windows Update Cleanup” is checked.

Press OK and let it go through and delete most of the file, at the end the dialog box will disappear but the Windows Update files will NOT have been deleted.

You need to reboot again, and this time you will see this message :


Once the system has rebooted you should have gained some disk space back :


SCCM OSD – Failed to Run Task Sequence (0X80004005)

I had a system delivered recently with a NIC which was dead on arrival. (Dell quality is going up and up!!)

An engineer attended site and replaced the motherboard. Next time I attempted to run OSD from PXE boot I encountered an error :

Failed to run Task Sequence (0X80004005)

So I looked in X:\Windows\temp\smsts.log and noticed :

SyncTimeWithMP() failed. 80004005.

The genius engineer had set the time wrong, or not at all – so when the machine was trying to make a secure connection with the management point it was failing!!

Setting the time correctly in the BIOS / firmeware resolved the issue.

Status Messages For an OSD Deployment

Troubleshooting OSD remotely can be difficult if the person initiating the build does not know how to get the logs from a failed machine.

This is a useful status message query to show all messages from the OSD process. It requires a Deployment ID, which is from the deployment of the task sequence you have a problem with.

from SMS_StatusMessage
left join SMS_StatMsgInsStrings
on SMS_StatMsgInsStrings.RecordID = SMS_StatusMessage.RecordID
left join SMS_StatMsgAttributes
on SMS_StatMsgAttributes.RecordID = SMS_StatusMessage.RecordID
where SMS_StatMsgAttributes.AttributeID = 401 and SMS_StatMsgAttributes.AttributeValue = "!!DEPLOYMENTID!!"
and SMS_StatMsgAttributes.AttributeTime >= ##PRM:SMS_StatMsgAttributes.AttributeTime## order by SMS_StatMsgAttributes.AttributeTime DESC

Replace !!DEPLOYMENTID!! with the deployment ID of the TS.