Diskpart script question

Discussion in 'Scripting' started by ciscokid, Aug 2, 2025 at 02:47.

  1. ciscokid

    ciscokid MDL Senior Member

    Jun 3, 2007
    354
    89
    10
    #1 ciscokid, Aug 2, 2025 at 02:47
    Last edited: Aug 2, 2025 at 03:04
    First off, let me say I am NOT a programmer by any means, just doing this for fun and to learn.

    I would like to put together a diskpart script to format a multi-partition flash drive to use for installing Windows 11.

    I know about Rufus, Ventoy and other programs which can do this but I want to learn by doing it myself.

    Basically, I'm going to have the first partition formatted as FAT32 with the boot files necessary to get to the installation screens. The second partition will be formatted using NTFS and hold all the data from the ISO.

    The first partition will have the folders boot and efi and files bootmgr and bootmgr.efi along with a "sources" folder containing only boot.wim, the second partition will have the entire ISO copied to it.

    I have created a flash drive manually using the above setup and it works perfectly.

    Here's the question: Since the flash drive will be a different disk number for each of my computers, can I add something at the beginning of the script that asks me for the disk number each time?

    These are the lines that will go into the script so far, just want to automate it if possible before calling the script, without having to enter the lines myself:

    select disk x
    clean
    convert mbr
    create partition primary size=1024
    format fs=fat32 quick label=BOOT
    active
    assign
    create partition primary
    format fs=ntfs quick label=SYSTEM
    assign
    exit
     
  2. Dark Vador

    Dark Vador X Æ A-12

    Feb 2, 2011
    4,695
    6,933
    150
    Disk part have option list disk
    And if you want, you can do it with ps
    That in this case also have options to view drive info
    So you can filter usb drive

    alternative implementation
    No args, script run disk part list disk
    Than using parameters , pass disk ID
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. ciscokid

    ciscokid MDL Senior Member

    Jun 3, 2007
    354
    89
    10
    #3 ciscokid, Aug 2, 2025 at 22:29
    Last edited by a moderator: Aug 3, 2025 at 10:45
    (OP)
    Yes! I did some more research online and found this batch file (made some modifications to suit what I needed):

    Would be nice to be presented with a list of drives but I'm just not that good LOL!!!

    I also learned how to inject the bypass registry keys manually into boot.wim so I'm learning a little every day!
    Code:
    @echo off
    set /p "DiskNum=Enter the Disk Number: "
    (
    echo SELECT DISK %DiskNum%
    echo CLEAN
    echo CREATE PARTITION PRIMARY SIZE=1024
    echo FORMAT FS=FAT32 QUICK LABEL=BOOT
    echo ASSIGN
    echo ACTIVE
    echo CREATE PARTITION PRIMARY
    echo FORMAT FS=NTFS QUICK LABEL=ISO
    echo ASSIGN
    
    ) > diskpart_script.txt
    
    diskpart /s diskpart_script.txt
    del diskpart_script.txt