If you want to run a script before the actual TS start, well even before the boot CD looks to SCCM for policies to run, you could add a Custom Media Hook. The Media Hook will run a script defined in an INI file and not enter TS mode before it has finished..
This could be useful in any number of scenarios like cleaning the disk, enabling the disk if it has been encrypted, setting variables, entering data to DB and so on and so on.
Now enabling this feature is quit simple, and then again it is not! confused? don’t be, cause here is an easy guide on how to work with the Custom Media Hook.
Step 1 (creating the necessary files)
1. Create an INI file called TSconfig.INI (this must be the name of the file or it will not work)
2. Edit the file to point to the script you want to run (in this case the script is called PreTS.vbs)
[CustomHook]
Commandline="x:\PreTS.vbs"
3. Create a PreTS.vbs script with the commands you want to have executed (in this example we enable an encrypted disk)
Option Explicit
On Error Resume NextDim oShell, oFso
Set oShell = CreateObject("WScript.Shell")
Set oFso = CreateObject("Scripting.FileSystemObject")‘»»»If there is no C-drive do to SafeGuarde encryption create one
If NOT oFso.folderExists("C:\") Then
oShell.Run "diskpart.exe /s x:\diskpart.txt",,true
End If
_____________________________-
To make sure the Media Hook integrated into the boot image that actually is on our DP we need to make changes to the original Boot.wim as the one we replicate to our DP is changed every time we integrate drivers into it (SCCM takes the original, injects the drivers into it and saves it as boot.”ID”.wim
Step 2 (placing the Media Hook files in the Boot File)
1. Mount the boot.wim file (properly found in C:\Program Files\Microsoft Configuration Manager\OSD\boot\i386\boot.wim)
imagex /mountrw “path”\boot.wim 1 C:\MOUNT
2. Add the files needed to the root folder ( same level as the windows folder)
3. Unmount the boot.wim commiting changes
imagex /unmount /commit C:\mount
4. update DP with a fresh copy of the boot.wim. It is important to update the DP as this action will create a new wim file. If you only refresh the existing boot.”id”.wim will be copied to the DP and the changes to the boot.wim will not be carried trough.
That’s it, the boot image will now run the PreTS.vbs before looking to SCCM for the TS to run..
You can of cause add other things to the boot.wim like trace32. exe or other thing useful during deployment, just mount-place-unmount
Can we make a media hook to change computer from domain? Let’s say during deployment of a machine, you can choose a domain the machine must come in?
Thanks Mate..
Really helpful
Keep adding useful stuff
We’re looking for a script to do some very complex things that hopefully will make the F12 & boot media options add TS variables that will make F12 & BM not just a bare-metal installation procedure, but also a re-image procedure an option as well. Things like querying the SCCM DB to get the SMS GUID, UUID, NetBIOS name, system architecture as well as querying to see if certain applications are installed, then display these returned values in an htm page and provide an option whether to do a bare-metal installation (& hence delete the computer object from the SCCM DB & AD) or insert these values into a TS and perform a re-image. Anyone heard of or have an example of a vbs or custom hta file to do anything like this?
I don’t know If I said it already but …I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks, 🙂
A definite great read….
Does anyone know exactly how the SCCM script starts to run within the winpe image? The MDT 2010 toolkit contains a xml file on the root of x: that runs a script in the deploy directory. I have looked everywhere in the Winpe boot image for SCCM and can not find anywhere that starts the deploy script. The startnet.cmd file does not contain anything to kick off the SCCM script so where is it?
I think what you’re looking for is the windowssystem32winpeshl.ini. Change it to something like the below:
[LaunchApps]
“x:windowssystem32cscript.exe”,”x:windowsSystem32prets.vbs”
%SYSTEMROOT%System32bddrun.exe,/bootstrap
The “x:windowssystem32cscript.exe” line tells it to use cscript to run the “x:windowsSystem32prets.vbs” file. After that’s done running it launches MDT in my case.
Does anybody knows how to inject the Winpeshl.ini into the bootmedia in SCCM? I have tried mounting the boot.wim placing the Winpeshl.ini in Windowssystem32 and also tried adding it to osdinjection.xml then updating the distribution point. But the X:Windowssystem32Winpeshl.ini is just replaced with the defaults without my changes.
[…] HDD and wipe it clean. For that we are going to use an example from Michael Peterson at this Link. Now you can burn your boot media and boot from your cd and kick off your TS which should […]
What did you put in your diskpart.txt file?
I second this question.
I think I found it:
select disk 0
clean
exit
Michael,
I am trying to setup a boot media for OSD. i have created the boot image from MDT selcting the check box “add media pre exeuction hook” and created the bootable media using the same boot iamge . when i boot i get the pop up for the computer name but not for the collection. i have followed several forums and blogs.
i want the bootable media to prompt for both computername and the collection name it should go to. in the articles about the same the techs suggest to create mdt boot image checkign the bos “add media pre execution hook” and specify the web service URL. i am not sure where to specify the URL
which files do i need to modify and what are the changes i need to do to allow WinPE call the web service?
please help
[…] also want to point out Michael Petersen blog on how to set up the Custom Media Hook, this posting explains the use of Custom Media Hook in detail so you can use it in other scenarios […]
How can use the same process in a refresh scenario? Booting 2000 laptops from a media would be painful…
thanks
Everything is very open with a precise explanation
of the challenges. It was definitely informative. Your website is extremely helpful.
Thanks for sharing!