When building a machine via a task sequence using either SCCM or MDT, there is no easy way to tell if a program has successfully installed or not. There is the option to halt the task sequence when an error occurs but this isn’t always preferable. you don’t always want a minor application halting the whole build.
Lets say that you want to make sure application A is installed before applications B and C get installed. We can always look at the file system to check if the files or folders are there, but this doesn’t guarantee that the application installed correctly, it might have copied the files but not added any registry settings or properly registered DLL’s.
A better way,is to look at exit state which the task sequence engine records in the registry. For this we can turn to PowerShell. This can be completed via script which is pretty straight forward with only one tricky bit, thrown in for fun.
The property that contains the status of a package is the _state key which resides in this location
HKLM\Software\WoW6432Node\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System\s0100100\GUIDLIKEKEY\_state
For some reason the _State property resides in a key that has a random GUID like name… not sure why, but it does. This means that it is impossible to enter the value as part of the script. Thankfully PowerShell helps get around this with two commands Get-childitem and Get-ItemProperty. Using these commands we can find out what the GUID key name is at run time, which then enables us to check the value of the _State.
This script can be run from a task sequence command line using the following arguments to supply the PackageID.
Powershell.exe Registrycheck.ps1 ‘S0100100’
$PackageID = $args
#Check to see if key exists if not the Get-Item property command will fail
$KeyCheck = Test-Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System\$PackageID'
#Get random GUID like key and create a variable called $mysterykey
$MysteryKey = (Get-ItemProperty (Get-ChildItem HKLM:"\Software\WoW6432Node\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System\$PackageID\").PsPath)._State
Now that we have got this information we can use it create task sequence variables to perform addition checks while the task sequence is running. For information on how this work and a script that can be modified check out this post http://www.industrialarcservices.com.au/2012/07/03/script-to-clean-up-statestore-folder-only-if-load-state-was-successful/
If you have any issues please feel free to comment or send me an email – Martin @Industrial Arc Services com au
Only packages create registry keys. Anything executed from a command line will not create these registry keys.