There’s a pretty good guide out there for making MDT automatically update WDS boot .wim files when you’re updating the media. Based on that, I took things one step further and scripted things so our virtual infrastructure gets the same automated treatment.
Prerequisites
- Your vSphere environment should be at least ESXi 4.x
- Install the latest version of PowerCLI from VMware. They’re entirely backwards compatible
- Run the Deployment Workbench with an account that has the appropriate roles and permissions to log into vCenter via PowerShell and upload files to a datastore. You have more options if you want to get tricky with PowerCLI (and you’ll have to explore those if you use ESXi with no vCenter manager!)
- These instructions assume you haven’t already tweaked things to automate uploading to WDS. I went this route because I did some things a little different than what was in the link above.
Make Magic Happen
- Where you installed MDT (probably C:Program FilesMicrosoft Deployment Toolkit) create a subfolder called Scripts
- Also where you installed MDT, open up the Templates folder and edit LiteTouchPE.xml (feel free to make a backup first!). Scroll down way to the bottom. Look for the Exits section and change the following:
- Original line: <Exit>cscript.exe “%INSTALLDIR%SamplesUpdateExit.vbs”</Exit>
- New Line: <Exit>cscript.exe “%INSTALLDIR%ScriptsUpdateExit.vbs”</Exit>
- Use Notepad to create two new files in your new Scripts folder
- UpdateExit.vbs
- Update-Vcenter.ps1
- Copy the contents at the bottom of this post into the appropriate script
- Make sure to change the parts of Update-Vcenter.ps1 that are in bold to reflect your environment – There are three things you need to chage: The vSphere server and the name of the DataStore you want your data uploaded to
That’s it! It’s working well for me in MDT 2012 Update 1 + ESXi 4.1. If you also want to do the WDS auto-update stuff, just update the UpdateExit.vbs script. If you’re having trouble, you can run the PowerShell script on its own. Just give it a file path/name as an argument and it’ll upload that file to your datastore.
UpdateExit.vbs Contents
‘ // ***************************************************************************
‘ //
‘ // Copyright (c) Microsoft Corporation. All rights reserved.
‘ //
‘ // Microsoft Deployment Toolkit Solution Accelerator
‘ //
‘ // File: UpdateExit.vbs
‘ //
‘ // Version: <VERSION>
‘ //
‘ // Purpose: “Update Deployment Share” exit script
‘ //
‘ // ***************************************************************************
Option Explicit
Dim oShell, oEnv, sCmd, rc
‘ Write out each of the passed-in environment variable values
Set oShell = CreateObject(“WScript.Shell”)
Set oEnv = oShell.Environment(“PROCESS”)
WScript.Echo “INSTALLDIR = ” & oEnv(“INSTALLDIR”)
WScript.Echo “DEPLOYROOT = ” & oEnv(“DEPLOYROOT”)
WScript.Echo “PLATFORM = ” & oEnv(“PLATFORM”)
WScript.Echo “ARCHITECTURE = ” & oEnv(“ARCHITECTURE”)
WScript.Echo “TEMPLATE = ” & oEnv(“TEMPLATE”)
WScript.Echo “STAGE = ” & oEnv(“STAGE”)
WScript.Echo “CONTENT = ” & oEnv(“CONTENT”)
‘ Do any desired WIM customizations (right before the WIM changes are committed)
If oEnv(“STAGE”) = “WIM” then
‘ CONTENT environment variable contains the path to the mounted WIM
End if
‘ Do any desired ISO customizations (right before a new ISO is captured)
If oEnv(“STAGE”) = “ISO” then
‘ CONTENT environment variable contains the path to the directory that
‘ will be used to create the ISO.
End if
‘ Do any steps needed after the ISO has been generated
If oEnv(“STAGE”) = “POSTISO” then
‘ CONTENT environment variable contains the path to the locally-captured
‘ ISO file (after it has been copied to the network).
sCmd = “C:windowsSystem32WindowsPowerShellv1.0powershell.exe -File “”C:Program FilesMicrosoft Deployment ToolkitScriptsUpdate-Vcenter.ps1″” ” & oEnv(“CONTENT”)
WScript.Echo “About to run command: ” & sCmd
rc = oShell.Run(sCmd, 0, true)
WScript.Echo “PowerShell rc = ” & CStr(rc)
WScript.Quit 1
End if
Update-Vcenter.ps1 Contents
Add-PSSnapIn VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer -Server your.vSphere.Server -ErrorAction Stop
$datastore = Get-Datastore “Your datastore”
New-PSDrive -Location $datastore -Name iso -PSProvider VimDatastore -Root “”
#Copy ISO to deployment share
foreach ($arg in $args) { Copy-DatastoreItem -Item $args -destination “iso:” }
#Cleanup
Remove-PSDrive iso
Remove-PSSnapIn VMware.VimAutomation.Core
Update: I realized there’s one weird situation where people following this might run into problems. If you have an NFS datastore, you may not be able to write to your datastore directly through vCenter. If that’s the case, you’ll want to connect directly to a ESXi host instead. Check out the New-VICredentialStore command for how to do this without storing your password in the script.