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 Next

Dim 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)

image

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