Recently I began exploring leveraging Prestart Commands in my Configuration Manager 2012 R2 environment. I’d previously leveraged them in the form of a “WebService Boot ISO” compliments of Maik Koster. I figured this would be no big deal, however I found my self running into troubles right out of the gate.
Specifically, the issue I ran into was not being able to load the Microsoft.SMS.TSEnvironment COM Object during the WinPE Prestart phase (before you select a Task Sequence). Now Technet provides some lovely documentation telling me that this is for sure possible and they even provide a nice little code snippet showing me that it should work. The only problem, when I try it, I get this ugly error in PowerShell:
Strange error so I start doing some searching and come across this forum posting:
Path not found. What??? How can this be? It’s always “just been there”.
Ok, enough whining, just call it from SysWOW64 directly.
Or not. The WindowsPowerShell directory doesn’t even exist! No 32-Bit instance of it is here! And for that matter no 32-bit instances of cmd.exe, cscript.exe, etc. I even confirmed this by mounting the boot image .wim file.
You may now be thinking “Just use DISM to load the 32-bit PowerShell components from the ADK”. Yeah, doesn’t work.
Just for good measure I loaded up a stock 64-bit MDT 2013 Boot Image (WinPE 5.0 of course) and same result.
Now here is the kicker. The Microsoft.SMS.TSEnvironment IS available during the preboot phase, BUT (you knew this was coming) you have a very limited window where this environment is accessible. If you are just trying to test out some code (before making permanent changes to your Boot Images), you can add a Prestart command to launch cmd.exe /k (The ‘/k’ keeps the command window open so you can test).
So long as you are executing your code leveraging this Prestart Method, you can access the Microsoft.SMS.TSenvironment.
I hope this helps someone out there. Took me a while to track this “limitation” down while testing out new code.