Michael Niehaus' Windows and Office deployment ramblings
You’ve probably gone through this cycle if you are using WDS to PXE boot computers to start bare metal Lite Touch deployments:
Fortunately, with the new “update” process in MDT 2010, described in more detail at http://blogs.technet.com/mniehaus/archive/2009/07/10/mdt-2010-new-feature-17-customizable-boot-image-process.aspx, it’s pretty simple to add a script to automate this process. First, the script:
Option Explicit Dim oShell, oEnv Set oShell = CreateObject("WScript.Shell") Set oEnv = oShell.Environment("PROCESS") If oEnv("STAGE") = "ISO" then Dim sCmd, rc sCmd = "WDSUTIL /Replace-Image /Image:""Lite Touch Windows PE (" & oEnv("PLATFORM") & ")"" /ImageType:Boot /Architecture:" & oEnv("PLATFORM") & " /ReplacementImage /ImageFile:""" & oEnv("CONTENT") & "\Sources\Boot.wim""" WScript.Echo "About to run command: " & sCmd rc = oShell.Run(sCmd, 0, true) WScript.Echo "WDSUTIL rc = " & CStr(rc) WScript.Quit 1 End if
Option Explicit
Dim oShell, oEnv
Set oShell = CreateObject("WScript.Shell") Set oEnv = oShell.Environment("PROCESS")
If oEnv("STAGE") = "ISO" then
Dim sCmd, rc
sCmd = "WDSUTIL /Replace-Image /Image:""Lite Touch Windows PE (" & oEnv("PLATFORM") & ")"" /ImageType:Boot /Architecture:" & oEnv("PLATFORM") & " /ReplacementImage /ImageFile:""" & oEnv("CONTENT") & "\Sources\Boot.wim""" WScript.Echo "About to run command: " & sCmd
rc = oShell.Run(sCmd, 0, true) WScript.Echo "WDSUTIL rc = " & CStr(rc)
WScript.Quit 1
End if
You’ll need to update the image name in the string above if you’ve changed it from the default of “Lite Touch Windows PE (x86)” and “Lite Touch Windows PE (x64)” since the script doesn’t know what you’ve changed the values to. Save the edited script as something like “C:\Scripts\UpdateExit.vbs”. Then, edit the “C:\Program Files\Microsoft Deployment Toolkit\Templates\LiteTouchPE.xml” file so that these lines:
<!-- Exits --> <Exits> <Exit>cscript.exe "%INSTALLDIR%\Samples\UpdateExit.vbs"</Exit> </Exits>
Instead look like this:
<!-- Exits --> <Exits> <Exit>cscript.exe "%INSTALLDIR%\Samples\UpdateExit.vbs"</Exit> <Exit>cscript.exe "C:\Scripts\UpdateExit.vbs"</Exit> </Exits>
Then make a change that requires re-generating the WIM and ISOs, e.g. change something in bootstrap.ini. You’ll see in the “Update Deployment Share” output the generated WDSUTIL command that updates the boot image in WDS. If WDS is located on a different server, you’ll need to update the command in the script above to add “/Server:WDSServerName” to the command. (WDSUTIL must also be available on the machine, so you may need to install the RSAT WDS tools.)
Extra credit for someone who can convert this into a PowerShell script and look up the right boot image name :-)
Hi Michael,
I just wanted to add some additional information about this process. In fact, because there isn't a "POSTWIM" phase it is necessary to do these automated process during "POSTISO" phase and require that "Generate a Lite Touch bootable ISO image" option have been enabled (for LiteTouch Image)
In addition it is required to have already added these boot images in WDS manually at least one time.
is it true ?
This script worked great until I created my first remote deployment share. When I updated the remote share's Boot.wim, The scripts stepped up and replaced my local boot images.
This resulted in local PXE boot.wim files that set the deployroot to the remote server share. Worked great but, very slow of course :)
I think I'll end up disabling the extension in the LiteTouchPE.xml file on the remote share and manually replacing files on those machines.
If I knew powershell, I think the solution would revolved around remote execution of WDSutil on the server specified in the DEPLOYROOT variable.
Powershell and I even got the image name! WDSUTIL doesn't seem to mind spaces in it's command line structure (odd but this script fails when I used quotes). Not bad for my first crack at Powershell scripting.
# The script:
#------------------------------
$Stage = (Get-ChildItem env:STAGE).value
If ($Stage -eq "ISO") {
$DeployRoot = (Get-ChildItem env:DEPLOYROOT).value
If ($DeployRoot -like "\\*\*") {
$DeploymentServer = $DeployRoot.split("\")[2] }
Else {
$DeploymentServer = (Get-ChildItem env:ComputerName).value
}
# Note that this script is called once for each platform image created (x86, x64)
$Platform = (Get-ChildItem env:PLATFORM).value
$Content = (Get-ChildItem env:CONTENT).value
# Determine the Name of the existing .wim file that exists in the WDS Share
$WDS_Share = "\\$DeploymentServer\" + (get-wmiobject win32_share -computername $DeploymentServer | where-object {$_.name -eq "REMINST"}).name
$ImageFileName = "$WDS_Share\Boot\$Platform\Images\" + (dir "$WDS_Share\Boot\$Platform\Images" *.wim).name
# Grab the 'Friendly Name' of the WDS Image File
$ImageName = (((wdsutil /get-imagefile /imagefile:$ImageFileName | select-string -inputobject {$_} -pattern "Image name:*").ToString()).split(":")[1]).trim()
# Run WDSUTIL to load the image on the server being updated.
WDSUTIL /replace-image /image:$ImageName /ImageType:Boot /Architecture:$Platform /ReplacementImage /ImageFile:$Content\LiteTouchPE_$Platform.wim /Server:$DeploymentServer
then adjust LiteTouchPE.xml:
<!-- Exits -->
<Exits>
<Exit>Powershell.exe "%deployroot%\Scripts\WDSupdate.ps1"</Exit>
</Exits>
Hi guys,
When i use the scirpt i have this message at the end of the update of the deploymentshare.
About to run command: WDSUTIL /Replace-Image /Image:"Lite Touch Windows PE (x86)" /ImageType:Boot /Architecture:x86 /ReplacementImage /ImageFile:"C:\Users\tissirm\AppData\Local\Temp\32\MDTUpdate.10468\ISO\Sources\Boot.wim" WDSUTIL rc = -1056702168 Exit code = 1
Can you help me?