Skip to main content
Home/Blog/Automation/diskpart Commands: Manage Disks and Partitions (2026)
Automation

diskpart Commands: Manage Disks and Partitions (2026)

Master diskpart commands to list disk, select disk, clean, create partition, and format fs=ntfs. Complete 2026 reference for Windows 10, 11 & Server — with hard safety warnings.

By InventiveHQ Team
diskpart Commands: Manage Disks and Partitions (2026)

Need to wipe, partition, or format a disk from the command line? diskpart is the built-in Windows utility for managing disks, partitions, and volumes — and because several of its commands erase entire drives, it demands more care than almost any other Windows tool.

diskpart Command Builder

Build diskpart scripts to list, clean, partition, format, and convert disks — with built-in verify steps and warnings so you do not wipe the wrong drive.

Open the full diskpart Command Builder
Loading interactive tool...

Verified June 2026 · tested on Windows 11 24H2, Windows 10 22H2 & Server 2022/2025

Warning — read this first. clean and clean all erase the entire selected disk, and selecting the wrong disk number means wiping the wrong drive. diskpart does not ask "are you sure?" Always run list disk, identify your target by size, then select disk N and confirm before any destructive command. Back up first.


Quick Reference: Essential Commands

Need to prep a blank disk right now? Here is the canonical "wipe, partition, format, assign" sequence:

diskpart                       :: launch the interactive utility (elevated)

list disk                      :: show every physical disk — note the SIZE
select disk 2                  :: target disk 2 (verify the size first!)
clean                          :: ERASES the selected disk's partition table
create partition primary       :: create one primary partition spanning the disk
select partition 1             :: select the partition you just made
format fs=ntfs quick           :: quick-format it as NTFS
assign letter=E                :: give it drive letter E:
exit                           :: leave diskpart

Which command do you need?

diskpart is interactive: you launch diskpart, then type one command per line. Almost every command operates on whatever object is currently selected, so selection mistakes are the #1 cause of data loss.


list: Inventory Disks, Volumes, and Partitions

The three list commands are how you see what you have before touching anything. Run list disk every single time before a destructive command.

Windows 10Windows 11Server 2016+Built in — no moduleNon-destructive

list Command Reference

CommandShows
list diskEvery physical disk: number, status, total size, free space, and * under Gpt for GPT disks
list volumeEvery volume (formatted partitions) with drive letter, label, filesystem, and size
list partitionPartitions on the currently selected disk (run select disk first)

list Usage Examples

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------   ---  ---
  Disk 0    Online          476 GB      0 B        *
  Disk 1    Online          1863 GB     0 B        *
  Disk 2    Online          14 GB    14 GB

DISKPART> select disk 2
DISKPART> list partition
DISKPART> list volume

Note: In the example above, Disk 2 is a 14 GB USB stick and Disk 0 is the 476 GB Windows system disk. The size column is your safety check — never trust the disk number alone, because numbers can change when drives are added or after a reboot.


select: Choose the Target Object

select sets the object that subsequent commands act on. There is a separate selection context for disk, partition, and volume. Getting this wrong is how the wrong drive gets erased.

Windows 10Windows 11Server 2016+⚠ Selection drives every destructive command

select Command Reference

CommandEffect
select disk NMake physical disk N the current disk
select partition NMake partition N (on the current disk) the current partition
select volume NMake volume N the current volume (can also use a drive letter: select volume E)
detail diskShow model, serial, and partitions of the selected disk — use it to confirm identity
detail partition / detail volumeShow details of the selected partition/volume

select Usage Examples

:: Always confirm BEFORE doing anything destructive
DISKPART> list disk
DISKPART> select disk 2
DISKPART> detail disk          :: verify model + serial match the drive you intend to wipe

:: Select a volume by its drive letter instead of number
DISKPART> select volume E

Warning: After select disk N, every later clean, create, format, or convert command hits that disk with no further confirmation. If you are unsure which disk is selected, run list disk again — the selected object is marked with an asterisk (*) in the leftmost column.


clean: Erase the Entire Disk

clean removes all partition, volume, and formatting information from the currently selected disk. This is the destructive heart of diskpart.

Windows 10Windows 11Server 2016+⚠ DESTROYS ALL DATA on the disk

clean Command Reference

CommandEffectSpeed
cleanDeletes the partition table and metadata sectors. File data remains on the platters until overwritten, but all partitions become inaccessibleSeconds
clean allZeros every sector on the disk — a secure wipe that makes data unrecoverableMinutes to hours depending on capacity

clean Usage Examples

:: Repurpose a disk quickly (data theoretically recoverable until overwritten)
DISKPART> list disk
DISKPART> select disk 2
DISKPART> clean

:: Securely wipe a disk before disposal/resale (zeros the whole drive)
DISKPART> select disk 2
DISKPART> clean all

Warning: clean and clean all erase the entire selected disk — not a single partition. There is no undo and no confirmation prompt. Selecting the wrong disk number wipes the wrong drive. Before running either, run list disk, confirm the size matches your target, and run detail disk to check the model/serial. Make sure you have a backup.

Warning: Never run clean against Disk 0 on a normal PC — that is almost always the disk Windows is running from. diskpart will refuse to clean a disk holding the running OS, but on a multi-disk or WinPE/Setup environment that protection may not apply.


create partition: Carve Out Space

After clean, the disk is empty. create partition allocates space; format makes it usable.

Windows 10Windows 11Server 2016+Built in — no module

create partition / format Reference

CommandEffect
create partition primaryCreate a primary partition using all remaining space (or add size=N for N megabytes)
create partition primary size=51200Create a 50 GB primary partition (size is in MB)
create partition extended / create partition logicalMBR-only: extended container and logical drives inside it
create partition efi size=100GPT system disks: 100 MB EFI System Partition
create partition msr size=16GPT system disks: Microsoft Reserved partition
format fs=ntfs quickQuick-format the selected partition as NTFS
format fs=fat32 quick label="DATA"Quick-format as FAT32 with a volume label
format fs=exfat quickQuick-format as exFAT (good for large cross-platform removable media)

create + format Usage Examples

:: One partition spanning the whole disk, NTFS, drive letter E:
DISKPART> select disk 2
DISKPART> create partition primary
DISKPART> select partition 1
DISKPART> format fs=ntfs quick label="Backup"
DISKPART> assign letter=E

:: A 50 GB partition, then the rest as a second partition
DISKPART> create partition primary size=51200
DISKPART> create partition primary

Note: Use quick for everyday formatting — it writes a fresh filesystem in seconds. Omitting quick performs a full format that also scans the entire surface for bad sectors, which can take a long time on large disks. A full format does not securely erase data the way clean all does.


assign: Give the Volume a Drive Letter

assign mounts the selected volume at a drive letter so Windows can use it. remove unmounts it.

Windows 10Windows 11Server 2016+Non-destructive

assign Command Reference

CommandEffect
assignAssign the next available drive letter automatically
assign letter=EAssign a specific drive letter (E:)
assign mount=C:\Mount\DataMount the volume at an empty NTFS folder instead of a letter
remove letter=ERemove the E: drive letter (volume stays intact, just hidden)

assign Usage Examples

DISKPART> select volume 3
DISKPART> assign letter=E

:: Hide a recovery/system volume by removing its letter
DISKPART> select volume 3
DISKPART> remove letter=E

Note: assign and remove only change how a volume is mounted — they do not erase data. Removing a letter is a safe way to hide a volume from users without deleting it.


active: Mark the Boot Partition (MBR only)

active flags the selected primary partition as the one the BIOS firmware boots from. It applies only to MBR disks.

MBR disks onlyLegacy BIOS boot⚠ Wrong partition = unbootable

active Command Reference

CommandEffect
activeMark the selected partition active (the system/boot partition)
inactiveClear the active flag from the selected partition

active Usage Examples

:: Make partition 1 bootable on a legacy-BIOS MBR disk
DISKPART> select disk 1
DISKPART> select partition 1
DISKPART> active

Warning: active only matters on MBR disks booting via legacy BIOS. GPT/UEFI systems ignore the active flag and boot from the EFI System Partition instead. Marking the wrong partition active — or setting it on a data disk — can leave Windows unable to boot. Only mark the partition that actually holds the boot files.


convert: Switch Between GPT and MBR

convert gpt and convert mbr change the partition style of the selected disk. The disk must be empty (no partitions) first.

Windows 10Windows 11Server 2016+⚠ Disk must be empty — usually requires clean

convert Command Reference

CommandEffectRequirement
convert gptConvert an empty disk to GUID Partition Table (needed for UEFI boot and disks > 2 TB)No partitions on disk
convert mbrConvert an empty disk to Master Boot Record (legacy BIOS / compatibility)No partitions on disk
convert dynamicConvert a basic disk to a dynamic disk
convert basicConvert an empty dynamic disk back to basicNo volumes on disk

convert Usage Examples

:: Convert a disk to GPT (clean first, which erases it)
DISKPART> select disk 2
DISKPART> clean
DISKPART> convert gpt

:: Convert back to MBR
DISKPART> select disk 2
DISKPART> clean
DISKPART> convert mbr

Warning: Because convert gpt/convert mbr require an empty disk, you almost always run clean first — which erases the entire disk. To convert a Windows system disk from MBR to GPT without data loss, use Microsoft's MBR2GPT.exe tool instead, not diskpart.


online/offline and attributes: Disk State

These commands control whether a disk is accessible and whether it is read-only — useful for SAN volumes, signature collisions, and write-protected media.

Windows 10Windows 11Server 2016+Non-destructive

online/offline & attributes Reference

CommandEffect
online diskBring the selected disk online (accessible to Windows)
offline diskTake the selected disk offline (hidden from Windows)
attributes diskShow the current attributes of the selected disk (read-only state, etc.)
attributes disk clear readonlyClear the read-only flag so the disk can be written
attributes disk set readonlyMake the disk read-only
attributes volume clear readonlyClear read-only on the selected volume

online/offline Usage Examples

:: Bring an offline disk online and make it writable
DISKPART> list disk
DISKPART> select disk 3
DISKPART> online disk
DISKPART> attributes disk clear readonly

:: Take a disk offline
DISKPART> select disk 3
DISKPART> offline disk

Note: A disk that reports offline is often the result of the SAN policy (Offline Shared on Server) or a disk signature collision with another connected disk. Bringing it online or clearing read-only does not erase data — these are safe state changes.


Troubleshooting: diskpart Errors and Gotchas

Each row is deep-linkable — share a specific error with …#dp-virtdisk, and the row highlights on arrival.

Message / SymptomMeaningFix
Access is denieddiskpart not running elevatedLaunch Command Prompt/PowerShell as Administrator (Start-Process diskpart -Verb RunAs)
Cannot clean a disk on which the current boot…Trying to clean the running Windows diskBoot from Windows Setup/WinPE and run diskpart from there
The media is write protectedDisk or volume has the read-only attribute setselect disk N then attributes disk clear readonly
Virtual Disk Service error: The disk is not emptyconvert gpt/mbr on a disk that still has partitionsRun clean first (erases the disk), then convert
The disk is offline because of policySAN policy or signature collision keeps the disk offlineselect disk N, online disk, then attributes disk clear readonly
There is no partition selectedRan format/active without selecting a partitionlist partition then select partition N first
The arguments specified for this command are not validWrong size= unit or value on create partitionSpecify size in MB (e.g. size=51200 for 50 GB), or omit it for max

Version-Specific & Compatibility Notes

  • Windows 10 / 11 & Server: diskpart is identical across modern versions and ships built in — no module or RSAT install required. Always run it from an elevated prompt.
  • GPT vs MBR: Use GPT for any disk over 2 TB and for UEFI boot disks; MBR only for legacy BIOS compatibility. The active command applies to MBR disks only.
  • System disk conversion: To convert the Windows boot disk from MBR to GPT without erasing it, use MBR2GPT.exe (Windows 10 1703+ and Windows 11), not diskpart convert.
  • PowerShell alternative: The Storage module (Get-Disk, Clear-Disk, New-Partition, Format-Volume, Set-Disk) does everything diskpart does and is scriptable. diskpart remains the fastest interactive option and is available in WinPE/Setup.
  • Scripting diskpart: Run a saved script non-interactively with diskpart /s C:\scripts\prep.txt. Test scripts on a disposable disk first — there is no confirmation prompt for destructive commands.
  • Recovery reality: After clean, partition-recovery tools (e.g. TestDisk) can sometimes rebuild the table if you stop writing to the disk immediately. After clean all, the disk is zeroed and data is unrecoverable. Treat every diskpart session as one keystroke away from data loss — back up first.

Frequently Asked Questions

Find answers to common questions

'clean' removes all partition and volume formatting information from the currently selected disk, leaving it uninitialized and unallocated. It does NOT zero every sector by default — 'clean all' does that. Either way, every partition on the selected disk becomes inaccessible, so all data is effectively erased. Always run 'list disk' and 'select disk N' and confirm the size before running clean.

'clean' only erases the partition table and boot/metadata sectors — the file data is left on the platters until overwritten, so it is fast (seconds). 'clean all' writes zeros to every sector on the disk, which securely wipes it but can take hours on a large HDD. Use 'clean' to repurpose a disk and 'clean all' when you need the data unrecoverable.

Select the volume or partition first, then run 'format fs=ntfs quick'. The full sequence on a blank disk is: select disk N, clean, create partition primary, select partition 1, format fs=ntfs quick, assign letter=X. Drop 'quick' for a full format that also scans for bad sectors (much slower).

Run 'list disk' first and identify your target by SIZE — not by number, because numbers can shift between reboots and when drives are added. Confirm the capacity matches the drive you intend to erase, then run 'select disk N'. Run 'detail disk' to double-check the model and serial before any destructive command like clean.

Select the disk, then run 'convert gpt'. The disk must contain NO partitions first, so you typically run 'clean' beforehand — which erases the disk. To go the other way use 'convert mbr'. To convert MBR to GPT without data loss on a Windows system disk, use MBR2GPT.exe instead, not diskpart.

Select the primary partition, then run 'active'. This marks it as the system partition that BIOS firmware boots from. 'active' only applies to MBR disks — GPT disks use the EFI System Partition instead and ignore the active flag. Marking the wrong partition active can make Windows unbootable.

Run 'list disk', 'select disk N', then 'online disk'. If the disk is read-only, also run 'attributes disk clear readonly'. Use 'offline disk' to take it offline. Disks can show offline due to a SAN policy or a signature collision with another disk.

After plain 'clean', the partition table is gone but the underlying file data remains until overwritten, so recovery tools like TestDisk can often rebuild partitions IF you stop using the disk immediately. After 'clean all', the disk is zeroed and recovery is not possible. Never count on recovery — back up before running diskpart.

diskpart requires an elevated (Administrator) Command Prompt or PowerShell. Right-click and 'Run as administrator', or launch with 'Start-Process diskpart -Verb RunAs'. You also cannot clean or format a disk that holds the running Windows installation or a locked volume — boot from Windows Setup or WinPE for those.

Transform Your IT with Automation

Streamline operations, reduce manual tasks, and improve security with intelligent automation.