Hello,
Here is a script that allows you to do a deployment while keeping a local copy of the image that is deployed.
I use it as a pre-installation task with an "empty" image
REM.-- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
:: Script of partitioning and copy in local of the image Wim
:: windows to be deployed in order not to request again
:: the network for a redeployment of the machine
:: ::
:: UEFI BOOT Partionning
:: Variables
:: Image index
SET IMAGE=181
:: Diskpart file path
SET DiskpartCommands=%TEMP%\Commands.txt
:: Recovery volume var initialisation
SET RECOVERY_VOL=""
:::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Script
:::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Search for the Recovery partition if it exists
CALL :Reco
:: If this partition does not exist, we repartition the hard disk
IF %RECOVERY_VOL%.==. CALL :Disk_Part
:: Detection of a possible windows partition to assign it the letter C:
CALL :DetectWindows
:: mounting the recovery partion under R:\
CALL :MountR %RECOVERY_VOL%
:: We check if the image to be deployed is already present, otherwise we copy it locally
CALL :SYNCIMAGE
:: Image deployment
CALL :Deploy
:: Copy of the recovery tools
CALL :COPYTOTOOLSPARTITION
:: End of script
GOTO :eof
:::::::::::::::::::::::::::::
:: Fonctions ::
:::::::::::::::::::::::::::::
:: Recovery partition detection
:Reco
SETLOCAL
for /f "tokens=2 delims= " %%V IN ('ECHO list volume ^| diskpart ^| find "Recovery"') DO SET VOL=%%V
ENDLOCAL & SET RECOVERY_VOL=%VOL%
GOTO :eof
:: Detection of a possible Windows partition
:DetectWindows
SETLOCAL
:: Looking for the partition letter associated with the Windows partition
:: If the associated letter is not C: we then look for the associated volume
for /f "tokens=2 delims= " %%V IN ('ECHO list volume ^| diskpart ^| find "Windows"') DO SET VOL=%%V
(
ECHO Select Volume %VOL%
ECHO ASSIGN LETTER=C
ECHO EXIT
) > %DiskpartCommands%
Diskpart /s %DiskpartCommands%
)
ENDLOCAL
GOTO :eof
:Disk_Part
:: Drive partioning
(
ECHO SELECT DISK 0
ECHO clean
ECHO convert gpt
ECHO rem == 1. System partition =========================
ECHO create partition efi size=100
ECHO format quick fs=fat32 label="System"
ECHO assign letter="S"
ECHO rem == 2. Microsoft Reserved partition =======
ECHO create partition msr size=16
ECHO rem == 3. Windows partition ========================
ECHO rem == a. Create the Windows partition ==========
ECHO create partition primary
ECHO rem == b. Create space for the recovery tools ===
ECHO rem == 10Go pour image ===
ECHO shrink minimum=10000
ECHO rem == c. Prepare the Windows partition =========
ECHO format quick fs=ntfs label="Windows"
ECHO assign letter="C"
ECHO rem === 4. Recovery partition ======================
ECHO create partition primary
ECHO format quick fs=ntfs label="Recovery"
ECHO set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
ECHO assign letter="R"
ECHO gpt attributes=0x8000000000000001
ECHO list volume
ECHO exit
) > %DiskpartCommands%
Diskpart /s %DiskpartCommands%
GOTO :eof
:: monting recovery partition
:MountR
(
ECHO Select Volume 3
ECHO ASSIGN LETTER=R
ECHO EXIT
) > %DiskpartCommands%
Diskpart /s %DiskpartCommands%
GOTO :eof
:: Copying image
:SYNCIMAGE
ROBOCOPY "Y:\wim\%IMAGE%" "R:\Kace" /MIR /R:0 /W:0 /NJH /NJS
GOTO :eof
:: Image deployment
:Deploy
format /q /y /s:enable /V:Windows /fs:ntfs c:
DISM /Apply-Image /ImageFile:R:\Kace\C_C.wim /Index:1 /ApplyDir:c:\
GOTO :eof
:COPYTOTOOLSPARTITION
@echo == Copy the Windows RE image to the Windows RE Tools partition ==
md R:\Recovery\WindowsRE
xcopy /y /h C:\Windows\System32\Recovery\Winre.wim R:\Recovery\WindowsRE\
@echo *********************************************************************
@echo == Register the location of the recovery tools ==
C:\Windows\System32\Reagentc /Setreimage /Path R:\Recovery\WindowsRE /Target C:\Windows
GOTO :eof
Comments