Copy an MDT Deployment Share to a USB without building a Media Share

By | March 27, 2017
Share

*Updated to support both x86/x64 boot wims.

This script copies an MDT Deployment Share to a USB drive and basically converts it to a media share in the process.  You must edit and update the “DrvLetter” variable. Please the batch file beside the “Deploy” folder.

@setlocal enableextensions enabledelayedexpansion
@echo off

REM Variables that require updating
SET OsWimName=101607_20170302
SET DrvLetter=E:

REM Optional Variables
REM Set to yes if you wish to delete the Os wims from Usb prior to update
SET DelOsWim=N

REM Do NOT change these variables
REM Get scriptdir withOUT trailing backslash
SET scriptdir=%~dp0
SET scriptdir=%scriptdir:~0,-1%
SET mountdir=c:\mnt
SET XF="LiteTouchPE*.wim" "*.iso" "*Media*.bat" MDT*.application *Sorter.ps1 CreateISO.bat autorun.inf
SET XD="%scriptdir%\Deploy\Working" "%scriptdir%\Deploy\Captures" "%scriptdir%\Deploy\Operating Systems"
SET UsbBootWim64=%~dp0Deploy\Boot\USBLtPe_x64.wim
SET UsbBootWim86=%~dp0Deploy\Boot\USBLtPe_x86.wim

REM Del existing Os Wims if exists, this makes sure that Rc doesn't fail on low disk space check
IF %DelOsWim%==Y (
IF EXIST "%DrvLetter%\Deploy\Operating Systems" RD "%DrvLetter%\Deploy\Operating Systems" /S /Q
)

REM Update all content excluding Os Imgs and Boot Imgs
echo Copy all content excluding OS wim...
robocopy "%scriptdir%" "%DrvLetter%" /e /purge /a-:hs /mt /purge /njh /njs /xf %XF% /xd %XD%

REM Copy ONLY the desired OS Wim
echo Copy Os wim files.
robocopy "%scriptdir%" "%DrvLetter%" %OsWimName%*.swm %OsWimName%*.wim /e /njh /njs
REM if error on wim may need to be split to fit on Fat32
IF %ERRORLEVEL% GTR 3 CALL :ERROR "failed(%ERRORLEVEL%) to copy Os image."

IF EXIST "%~dp0Deploy\Boot\LiteTouchPE_x64.wim" (
echo Begin updating Boot wims Bs ini...
REM Bootx64 Section
xcopy "%~dp0Deploy\Boot\x64" "%DrvLetter%\" /HEYI
REM Copy Orig LiteTouchPE Wim to begin creating media Wim
copy "%~dp0Deploy\Boot\LiteTouchPE_x64.wim" "%UsbBootWim64%" /Y
REM Mount USBLtPe_x64.wim to inject media bootstrap.ini
IF NOT EXIST "%mountdir%" (md "%mountdir%")
dism /mount-image /imagefile:"%UsbBootWim64%" /index:1 /mountdir:"%mountdir%"
IF %ERRORLEVEL% GTR 3 CALL :ERROR "failed(%ERRORLEVEL%) to mount %UsbBootWim64% wim."

REM Overwrite Bootstrap,ini file in Boot wim
echo [Settings]> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo Priority=Default>> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo [Default]>> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo SkipBDDWelcome=YES>> "%mountdir%\Deploy\scripts\Bootstrap.ini"

REM Unmount Litetouch WIM image
echo Un-mount updated boot wim...
dism /unmount-image /mountdir:%mountdir% /commit
REM if error on unmount, exit script
IF %ERRORLEVEL% GTR 3 CALL :ERROR "failed(%ERRORLEVEL%) to un-mount %UsbBootWim64% wim."

call :UpdateBcd LiteTouchPE_x64.wim
)

IF EXIST "%~dp0Deploy\Boot\LiteTouchPE_x86.wim" (
REM Bootx64 Section
xcopy "%~dp0Deploy\Boot\x86" "%DrvLetter%\" /heyi
REM Copy Orig LiteTouchPE Wim to begin creating media Wim
copy "%~dp0Deploy\Boot\LiteTouchPE_x86.wim" "%UsbBootWim86%" /y
REM Mount USBLtPe_x64.wim to inject media bootstrap.ini
IF NOT EXIST "%mountdir%" (md "%mountdir%")
dism /mount-image /imagefile:"%UsbBootWim86%" /index:1 /mountdir:"%mountdir%"
IF %ERRORLEVEL% GTR 3 CALL :ERROR "failed(%ERRORLEVEL%) to mount %UsbBootWim86% wim."

REM Overwrite Bootstrap,ini file in Boot wim
echo [Settings]> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo Priority=Default>> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo [Default]>> "%mountdir%\Deploy\scripts\Bootstrap.ini"
echo SkipBDDWelcome=YES>> "%mountdir%\Deploy\scripts\Bootstrap.ini"

REM Unmount Litetouch WIM image
dism /unmount-image /mountdir:%mountdir% /commit
REM if error on unmount, exit script
IF %ERRORLEVEL% GTR 0 CALL :ERROR "failed(%ERRORLEVEL%) to un-mount %UsbBootWim86% wim."

call :UpdateBcd LiteTouchPE_x86.wim
)

:OverwriteBootWims
IF EXIST "%UsbBootWim64%" (
copy "%UsbBootWim64%" "%DrvLetter%\Deploy\Boot\LiteTouchPE_x64.wim" /Y
del "%UsbBootWim64%" /F /Q
)
IF EXIST "%UsbBootWim86%" (
copy "%UsbBootWim86%" "%DrvLetter%\Deploy\Boot\LiteTouchPE_x86.wim" /Y
del "%UsbBootWim86%" /F /Q
)

REM Create media.tag file
echo.> "%DrvLetter%\Deploy\Scripts\media.tag"

REM Overwrite Bootstrap,ini file outside of Boot wim
echo [Settings]> "%DrvLetter%\Deploy\Control\Bootstrap.ini"
echo Priority=Default>> "%DrvLetter%\Deploy\Control\Bootstrap.ini"
echo [Default]>> "%DrvLetter%\Deploy\Control\Bootstrap.ini"
echo SkipBDDWelcome=YES>> "%DrvLetter%\Deploy\Control\Bootstrap.ini"

label %DrvLetter% %OsWimName%

echo Script completed with no errors...
pause
exit

:UpdateBcd
echo Begin updating of Bcd entries...
DEL "%DrvLetter%\Boot\BCD" /F /Q
%WinDir%\System32\bcdedit.exe -createstore %DrvLetter%\Boot\BCD
SET BCDEDIT=bcdedit -store "%DrvLetter%\Boot\BCD"
%BCDEDIT% -create {ramdiskoptions} -d "Ramdisk options"
%BCDEDIT% -set {ramdiskoptions} ramdisksdidevice boot
%BCDEDIT% -set {ramdiskoptions} ramdisksdipath \Boot\boot.sdi
FOR /f "tokens=3" %%a in ('%BCDEDIT% -create -d "WinPE" -application osloader') do set GUID=%%a
%BCDEDIT% -set %GUID% systemroot \Windows
%BCDEDIT% -set %GUID% detecthal Yes
%BCDEDIT% -set %GUID% winpe Yes
%BCDEDIT% -set %GUID% osdevice ramdisk=[boot]\Deploy\Boot\%1,{ramdiskoptions}
%BCDEDIT% -set %GUID% device ramdisk=[boot]\Deploy\Boot\%1,{ramdiskoptions}
%BCDEDIT% -create {bootmgr} -d "Windows Boot Manager"
%BCDEDIT% -set {bootmgr} timeout 30
%BCDEDIT% -set {bootmgr} displayorder %GUID%
exit /b 0

:ERROR
echo %1
pause
exit /b 0

/BG

2 thoughts on “Copy an MDT Deployment Share to a USB without building a Media Share

  1. Manoj

    Firstly, I would like to thank you for sharing your wealth of information on tips and tricks on how to enhance the use of MDT. I have a request and hope you may be able to assist.

    I have configured a MDT setup that I maintain for my home lab and I use it for patching the reference images (WIM) of Win10/WS2016. Do you know if it is possible to export the entire contents inside the MDT share to include the OS, Apps, Control, Task Sequences as a zipped bundle . And be able to import the bundle into say a newly build server MDT server.

    I know I could simply take a copy of the the entire MDT folder and paste it on the new server. What I am looking to acheive is if I could create a package I can provide it someone with a bunch of silent MDT install files and they can restore my configuration.

    Thanks!

    Reply
    1. Brian Gonzalez Post author

      Manoj, MDT has some really useful Powershell applets. I would start there. They could easily mass import OS items and apps, the Task Sequences though might be a hassle, but in essence they are just XML files.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.