Here are some scripts I use in our environment, They account for quite a few scenarios but have some variable dependencies that must be defined before running it. The recovery partitions are configured to meet bitlocker deployment requirements so you don't have to fight with that later if you choose to leverage bitlocker.
%BOOTMODE%: BIOS/UEFI
%OS_DISK%: Usually 0, but if you have multiple drives and need to target a specific one, you can set the value accordingly.
%SHRINK_OS_VOLUME%: If for some reason you needed to shrink the windows volume by x to append an additional partition this is a control for that.
%SHRINK_OS_VOL_SIZE%: Size in MB to shrink the OS volume for the purposes of appending additional partitions.
%RECOVERY_IMAGE%: If you wanted to define a custom recovery image partition, you could do so by defining this value.
4K SECTOR SUPPORT: Comments are provided for achieving 4k sector support.
If you dont define BOOTMODE or OS_DISK, the script will fail. The other variables are optional depending on your specific needs.
The script assumes drive letters R, S, and W are not already assigned to other drives/volumes.
Volume/Partition letter assignment after the format procedure is complete are as follows:
R: - Recovery Partition
S: - System Partition
W: - Windows Parititon
This allows you to easily and statically target volumes pre or post image deployment.
Let me know if you need further assistance with this, and I would be glad to help.
Also if this happens to solve your issue, kindly mark it as a solution. Thanks in advance :)
:DISKPART
cls
echo.
echo * STARTING %BOOTMODE% FORMAT OF DISK %OS_DISK%...
if /i "%BOOTMODE%" EQU "BIOS" (
echo select disk ^%OS_DISK%>x:\diskpart.txt
echo clean>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 1. WINDOWS RE TOOLS PARTITION - 500MB>>x:\diskpart.txt
echo create partition primary size=500>>x:\diskpart.txt
echo format quick fs=ntfs label="Recovery">>x:\diskpart.txt
echo set id=27>>x:\diskpart.txt
echo assign letter=R>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 2. SYSTEM RESERVED - 100MB>>x:\diskpart.txt
echo REM ** NOTE - For 4K sector drives change size to 260 **>>x:\diskpart.txt
echo create partition primary size=100>>x:\diskpart.txt
echo format quick fs=ntfs label="System">>x:\diskpart.txt
echo active>>x:\diskpart.txt
echo assign letter=S>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 3. WINDOWS PARTITION - REMAINING DRIVE SPACE>>x:\diskpart.txt
echo create partition primary>>x:\diskpart.txt
if defined SHRINK_OS_VOLUME (
echo shrink minimum=%SHRINK_OS_VOL_SIZE%>>x:\diskpart.txt
)
echo format quick fs=ntfs label="OS">>x:\diskpart.txt
echo assign letter=W>>x:\diskpart.txt
if defined RECOVERY_IMAGE (
echo.>>x:\diskpart.txt
echo REM 4. Recovery image partition.>>x:\diskpart.txt
echo create partition primary>>x:\diskpart.txt
echo format quick fs=ntfs label="Recovery image">>x:\diskpart.txt
echo assign letter=T>>x:\diskpart.txt
)
echo.>>x:\diskpart.txt
echo list partition>>x:\diskpart.txt
echo list volume>>x:\diskpart.txt
echo exit>>x:\diskpart.txt
)
if /i "%BOOTMODE%" EQU "UEFI" (
echo select disk ^%OS_DISK%>x:\diskpart.txt
echo clean>>x:\diskpart.txt
echo convert gpt>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 1. WINDOWS RE TOOLS PARTITION - 500MB>>x:\diskpart.txt
echo create partition primary size=500>>x:\diskpart.txt
echo format quick fs=ntfs label="Recovery">>x:\diskpart.txt
echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac">>x:\diskpart.txt
echo assign letter=R>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 2. SYSTEM EFI PARTITION - 100MB>>x:\diskpart.txt
echo REM ** NOTE - For 4K sector drives change efi size to 260 **>>x:\diskpart.txt
echo create partition efi size=100>>x:\diskpart.txt
echo format quick fs=fat32 label="System">>x:\diskpart.txt
echo assign letter=S>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 3. MICROSOFT RESERVED MSR PARTITION - 128MB>>x:\diskpart.txt
echo create partition msr size=128>>x:\diskpart.txt
echo.>>x:\diskpart.txt
echo REM 4. WINDOWS PARTITION - REMAINING DRIVE SPACE>>x:\diskpart.txt
echo create partition primary>>x:\diskpart.txt
if defined SHRINK_OS_VOLUME (
echo shrink minimum=%SHRINK_OS_VOL_SIZE%>>x:\diskpart.txt
)
echo format quick fs=ntfs label="OS">>x:\diskpart.txt
echo assign letter=W>>x:\diskpart.txt
if defined RECOVERY_IMAGE (
echo.>>x:\diskpart.txt
echo REM 5. Recovery image partition.>>x:\diskpart.txt
echo create partition primary>>x:\diskpart.txt
echo format quick fs=ntfs label="Recovery image">>x:\diskpart.txt
echo assign letter=T>>x:\diskpart.txt
)
echo.>>x:\diskpart.txt
echo list partition>>x:\diskpart.txt
echo list volume>>x:\diskpart.txt
echo exit>>x:\diskpart.txt
)
ping 127.0.0.1 -n 3 > nul
diskpart /s x:\diskpart.txt