Build diskpart scripts to list, clean, partition and format disks safely.
diskpart is the built-in Windows command-line disk partitioner. It lists, creates, formats, and wipes disks, partitions, and volumes — jobs the graphical Disk Management console sometimes cannot do, such as cleaning a protected USB drive or converting between GPT and MBR. Because it operates at the disk level with no undo, this builder always starts with list disk so you confirm the target by its size before any destructive step.
clean erases the entire selected disk and format wipes the selected volume. Selecting the wrong disk number is unrecoverable. Always run list disk first and verify the disk by its size, not just its number, before continuing.
You enter diskpart to open its own prompt, then run commands one line at a time. You first select an object (a disk, partition, or volume), and every following command acts on that selection until you select something else. That two-step select-then-act model is why picking the wrong disk is so dangerous.
List everything:
diskpart
list disk
list volume
list partitionWipe and partition a new disk:
list disk
select disk 1
clean
create partition primary
format fs=ntfs quick
assign letter=EConvert a cleaned disk to GPT:
select disk 1
clean
convert gpt| Command | Purpose |
|---|---|
select disk N | Choose the disk to act on |
clean | Remove all partitions (clean all zeros every sector — slow) |
create partition primary | Create a primary partition |
format fs=ntfs quick | Quick-format the volume as NTFS |
assign letter=E | Give the volume a drive letter |
convert gpt / convert mbr | Switch partition style (disk must be empty) |
list disk is your safest check.quick format is fine for reuse; omit it for a full format that also checks for bad sectors.clean all zeroes every sector and can take hours on a large drive, but it fully erases data and is appropriate before disposing of a disk.Open diskpart as Administrator, run list disk and confirm the target by its size, then select disk N and clean. The clean command removes all partitions and volume information. Use clean all to zero every sector for a full, irreversible erase, which is slower.
clean operates on a whole disk and removes its entire partition layout, leaving it unallocated. format operates on a single selected volume and writes a fresh file system to it. clean wipes the structure of the disk, while format prepares one volume for use.
The disk must be empty first. Select it with select disk N, run clean to remove all partitions, then run convert gpt or convert mbr. Converting destroys existing data, so back up anything important before you start.
Always run list disk before any destructive command and identify the target by its capacity, not just its number, because disk numbers can shift between reboots. The select then act model means every command hits the last selected disk, so confirm the selection each time.