Basically it queries a registry key in WinPE to determine whether the boot was UEFI or Legacy and then runs one of 2 diskpart scripts depending on the outcome. I also wanted it self contained so the diskpart scripts are written on the fly rather than kept as dependencies
IF %ERRORLEVEL% == 0 goto UEFI
IF %ERRORLEVEL% == 1 goto BIOS
goto END
:UEFI
(
ECHO select disk 0
ECHO clean
ECHO convert basic noerr
ECHO convert gpt noerr
ECHO create partition efi size=200
ECHO assign letter=s
ECHO format quick fs=FAT32
ECHO create partition msr size=128
ECHO create partition primary
ECHO assign letter=c
ECHO format quick fs=NTFS
ECHO exit
)>X:\Windows\System32\UEFI.txt
diskpart /s X:\Windows\System32\UEFI.txt
goto END
:BIOS
(
ECHO select disk 0
ECHO clean
ECHO convert basic noerr
ECHO convert mbr noerr
ECHO create partition primary size=500
ECHO select partition 1
ECHO active
ECHO assign letter=s
ECHO format quick fs=NTFS
ECHO create partition primary
ECHO select partition 2
ECHO assign letter=c
ECHO format quick fs=NTFS
ECHO exit
)>X:\Windows\System32\BIOS.txt
diskpart /s X:\Windows\System32\BIOS.txt
bootsect.exe /NT60 c:
goto END
:END
Obviously the diskpart commands can be changed to suit whatever your needs. Hopefully will help someone!
Obviously provided as is with no support.
For a cleaner way of doing it you may replace "X:\Windows\System32" by "%TEMP%" . - gwir 7 years ago
Things I would check:
When it fails can you manually find the REG key in the first line? Is the X:\ path available? If not change to %TEMP%\ - rjonesdj 7 years ago