Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for WinPE to auto deploy a Windows 10 image.
echo select disk 0 > diskpart%ID%.txt
echo clean >> diskpart%ID%.txt
echo ** Creating system reserved partition...
echo create partition primary size=500 >> diskpart%ID%.txt
echo select partition 1 >> diskpart%ID%.txt
echo active >> diskpart%ID%.txt
echo format quick fs=ntfs >> diskpart%ID%.txt
echo assign letter="r" >> diskpart%ID%.txt
echo ** Creating OS partition...
echo create partition primary >> diskpart%ID%.txt
echo select partition 2 >> diskpart%ID%.txt
echo active >> diskpart%ID%.txt
echo format quick fs=ntfs >> diskpart%ID%.txt
echo assign letter="c" >> diskpart%ID%.txt
echo select partition 1 >> diskpart%ID%.txt
echo active >> diskpart%ID%.txt
echo ** Executing diskpart script...
diskpart /s diskpart%ID%.txt
del diskpart%ID%.txt
echo ** Mounting network share...
net use j: \\server\share /user:username "password"
echo ** Applying Windows reserved partition...
Dism /apply-image /imagefile:j:\w10reserved.wim /index:1 /ApplyDir:r:\
echo ** Applying Windows main partition...
Dism /apply-image /imagefile:j:\w10.wim /index:1 /ApplyDir:c:\
copy /Y j:\SetupComplete.cmd c:\windows\setup\scripts\SetupComplete.cmd
@jjloud

This comment has been minimized.

Copy link

jjloud commented Mar 16, 2018

I love this script. It's a great way to deploy windows using WinPE and a network share. However, I'm having trouble launching windows after successful execution of the script. DISM goes fine and the files are on the drive. But my Boot Configuration Data is missing.

Do you have any advice on how to fix the Boot Installation Data either in the image or the script? The computer loads up and complains its missing. I've tried using the windows setup utility to use Bootrec and fix it that way but it doesn't work.

The only way I can get a successful deployment to work is to first start the installation of windows using the standard setup. Then exiting the setup, and then running DISM to copy the image over. I'd like to use this script instead!

Any help is appreciated.

@jvmraa

This comment has been minimized.

Copy link

jvmraa commented Apr 21, 2018

I'm trying to create a script in uefi mode with the option to select the partition disk but I need a hand

@echo OFF
CLS
ECHO Prepare Hard Disk for uefi setup
ECHO ----------------------------------------
ECHO list disk > list.txt
diskpart /s list.txt
DEL list.txt>nul
ECHO.
SET /p disk="Which disk number would you like to prepare?"
ECHO.
ECHO --WARNING-- This will FORMAT the selected disk and ERASE ALL DATA
ECHO.
ECHO You selected disk ---^> %disk%
ECHO.
CHOICE /C YN /M "Is this correct "
IF %ERRORLEVEL% == 1 GOTO INIT
CLS
ECHO Preperation Aborted, No changes have been made...
ECHO.
PAUSE
EXIT
:INIT
ECHO sel dis %disk% > init.txt
ECHO clean >>init.txt
ECHO convert pgt >> init.txt
ECHO create partition efi size=100 >> init.txt
ECHO format quick fs=fat32 label="System" >> init.txt
ECHO assign letter="S" >> init.txt
ECHO create partition msr size=16 >> init.txt
ECHO create partition primary >> init.txt
ECHO shrink minimum=500 >> init.txt
ECHO format quick fs=ntfs label="Windows" >> init.txt
ECHO assign letter="W" >> init.txt
ECHO create partition primary >> init.txt
ECHO format quick fs=ntfs label="Recovery tools" >> init.txt
ECHO assign letter="R" >> init.txt
ECHO set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >> init.txt
ECHO gpt attributes=0x8000000000000001>> init.txt
ECHO exit >> init.txt
:RUN
CLS
diskpart /s init.txt
DEL init.txt >nul
ECHO.
ECHO This drive is now prepared for WinNTSetup_X64.exe
ECHO.
PAUSE
EXIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.