How to use DISKPART commands in Windows 11/10

To use DISKPART in Windows 11 or Windows 10, open Command Prompt as administrator, type diskpart, run list disk, pick a target with select disk <n>, and then type the command you need.

Advertisement

This guide lists every DISKPART command, walks through the common jobs such as wiping a USB drive or resizing a volume, and covers scripts, safety rules, errors and two related tools: sxstrace and WMIC.

DISKPART window listing two disks after the select disk command
Selecting a disk targets every later command at it until you choose a different object. (Image: Microsoft)

How to use Diskpart command in Windows 11/10?

DISKPART works on focus: you list objects, select one, and every later command acts on that selection until you pick another.

The sequence below formats an empty disk as NTFS, which is the example Microsoft uses in its own reference.

  1. Select Start, type cmd, then select Run as administrator and choose Yes in the User Account Control prompt.
  2. Type diskpart and press Enter. The prompt changes to DISKPART>.
  3. Type list disk and press Enter to see every disk with its number, size and free space.
  4. Type select disk 1 (use your own disk number) and press Enter. An asterisk marks the selected disk in the next listing.
  5. Type create partition primary to create a partition across the free space.
  6. Type format fs=ntfs label=Backup quick to quick-format it as NTFS with the label Backup.
  7. Type assign to give the new volume the next free drive letter, then type exit to leave DISKPART.

Check the disk number twice before step 4. DISKPART does not ask for confirmation, so a wrong number hits the wrong drive.

DISKPART prompt after creating a partition and formatting it NTFS
DiskPart confirms success right after the format fs=ntfs label=Backup quick command completes, matching Microsoft's own example. (Image: Microsoft)

What is DISKPART?

DISKPART is the built-in command interpreter for managing disks, partitions, volumes and virtual hard disks (VHDs). It ships with Windows 11, Windows 10 and Windows Server.

Fact Detail
Permission needed Membership of the local Administrators group, or a group with similar rights
How it targets objects You give an object focus with select; commands then act on that object
Automatic focus changes Creating a partition moves focus to the new partition
Linked focus Selecting a volume on a basic disk also selects its partition and disk
Focus marker An asterisk (*) appears next to the selected object after any list command
Missing disks A missing disk shows with an M prefix, for example M0

Accessing DISKPART in Windows 11/10

Every route needs an elevated session, because DISKPART refuses to run without administrator rights.

Where you start What to do Result
Start menu Search cmd, select Run as administrator, then type diskpart Interactive DISKPART session inside Command Prompt
Windows Terminal or PowerShell Open it as administrator and type diskpart Same session; DISKPART runs inside PowerShell
Run dialog Press Win + R, type diskpart, press Enter and approve the prompt DISKPART opens in its own console window
A saved script Run diskpart /s scriptname.txt from an elevated prompt Commands run unattended, one per line

For more quick-launch names like this, see the complete list of Windows 11 Run commands.

Advertisement

List of Diskpart Commands in Windows 11/10

Type help inside DISKPART to print this list, or help <command> for the syntax of one command.

Command What it does
active Marks the partition with focus as active
add Mirrors the simple volume with focus to another disk
assign Assigns a drive letter or mount point to the volume with focus
attach vdisk Mounts a VHD so it appears as a local disk
attributes Displays, sets or clears disk or volume attributes such as read-only
automount Turns the automount feature on or off
break Splits a mirrored volume into two simple volumes
clean Removes all partition or volume formatting from the disk with focus
compact vdisk Reduces the physical size of a dynamically expanding VHD file
convert Changes a disk between MBR and GPT, or basic and dynamic
create Creates a partition, a volume or a VHD
delete Deletes a partition or a volume
detach vdisk Stops a VHD from appearing as a local disk
detail Shows information about the selected disk, partition, volume or VHD
exit Closes DISKPART
expand vdisk Grows a VHD to the size you set
extend Extends the volume or partition with focus into free space that follows it
filesystems Shows the current file system and the ones available for formatting
format Formats the volume with focus so it can store files
gpt Assigns GPT attributes to the partition with focus
help Lists commands or shows help for one command
import Imports a foreign disk group
inactive Marks the system or boot partition as inactive on MBR disks
list Lists disks, partitions, volumes or VHDs
merge vdisk Merges a differencing VHD with its parent
offline / online Takes a disk or volume offline, or brings it back online
recover Refreshes disks in a disk group and resynchronises mirrored and RAID-5 volumes
rem Marks a comment line in a script
remove Removes a drive letter or mount point
repair Repairs a RAID-5 volume by replacing the failed disk region
rescan Looks for newly added disks
retain Prepares a dynamic simple volume for use as a boot or system volume
san Displays or sets the storage area network policy
select Moves focus to a disk, partition, volume or VHD
set id Changes the partition type field
shrink Reduces the size of the selected volume
uniqueid Displays or sets the GPT identifier or MBR signature of a disk

Basic Commands and Usage

Four commands do most of the work: list to see objects, select to focus one, detail to inspect it, and exit to leave.

list disk shows size, free space, basic or dynamic type and MBR or GPT style. list volume shows volumes on all disks, and list partition shows partitions on the selected disk.

list volume
select volume=c
detail volume

list volume numbers every volume. select volume= accepts the volume number, a drive letter or a mount-point path. detail volume then prints the disks and attributes behind the selected volume.

Advertisement

You should see: DISKPART replies "Volume N is the selected volume", and the next list volume shows an asterisk beside it.

DISKPART console showing the list command's disk, partition, volume options
Typing list alone shows these four object types; add a noun like disk or volume to list one. (Image: Microsoft)

Practical Usage Scenarios

Match your job to a row, select the object shown in the second column first, then run the commands in order.

What you want to do Select first Commands to run
List drives and see free space Nothing list disk, then list volume
Wipe and reformat a USB drive or spare disk select disk <n> clean, create partition primary, format fs=ntfs quick, assign
Delete a volume or partition select volume <n> or select partition <n> delete volume or delete partition
Assign a drive letter to a partition with none select volume <n> assign letter=e
Remove a drive letter select volume <n> remove letter=e
Reduce the size of a partition select volume <n> shrink querymax, then shrink desired=<MB>
Grow a volume into free space after it select volume <n> extend or extend size=<MB>
Erase a disk so data cannot be read back select disk <n> clean all (writes zeros to every sector)
Convert an empty MBR disk to GPT select disk <n> clean, then convert gpt
Clear a write-protected disk flag select disk <n> attributes disk clear readonly

clean erases only the partition table, which makes the data unreachable but not overwritten. clean all zeroes every sector and takes far longer on large drives.

Advanced Commands and Techniques

Scripts let you repeat a disk layout exactly, which is how Windows deployment teams build recovery partitions. Put one command per line with no blank lines, and start comment lines with rem.

Advertisement

Add noerr to a command in a script to keep going after an error. DISKPART still stops on syntax errors, whatever noerr says.

  1. Open Notepad and type the commands, for example select disk 1, clean, convert gpt, create partition primary size=300, format quick fs=ntfs label=Tools and assign letter=T, each on its own line.
  2. Save the file as layout.txt in a folder you can reach, such as D:\scripts.
  3. Open Command Prompt as administrator.
  4. Run diskpart /s D:\scripts\layout.txt to execute the script.
  5. Run diskpart /s D:\scripts\layout.txt > D:\scripts\log.txt instead when you want the output saved to a log file.
  6. Wait at least 15 seconds before starting a second DISKPART script, or add timeout /t 15 between them in a batch file.

Other advanced commands: attach vdisk and detach vdisk mount and unmount VHD files, san sets the policy for newly found disks, and uniqueid disk reads or changes a disk signature. PowerShell covers the same ground with storage cmdlets such as Clear-Disk and Resize-Partition.

Safety Precautions and Best Practices

DISKPART acts immediately and has no undo, so the checks happen before you press Enter.

Risk What happens Precaution
Wrong disk selected clean wipes the partition table of whatever disk has focus Run list disk and match the size before select disk; unplug drives you do not need
Deleting partitions on a dynamic disk Can delete every dynamic volume on the disk and leave it corrupt Use delete volume for dynamic volumes, never delete partition
delete partition override Removes any partition type, including OEM and recovery partitions Use it only when you know what the partition holds
create partition ... id= A wrong partition type can stop the PC from starting Leave id= out; use create partition efi or msr for those types
Converting to GPT Fails unless the disk is empty Back up data first, then clean the disk
Shrinking a volume Only NTFS or unformatted volumes shrink Run shrink querymax to see the safe maximum first

How to check a DISKPART change worked

  1. Type list disk and confirm the free space column changed as expected.
  2. Type list volume and check the drive letter, file system (NTFS, FAT32) and size of the new or resized volume.
  3. Type detail disk with the disk still selected to see every volume on it.
  4. Type exit, then open File Explorer and confirm the drive appears under This PC with its new label.
  5. Right-click the drive, select Properties and check Capacity matches the size you set.

Common Errors and Troubleshooting

DISKPART will not open from Command Prompt

The session is not elevated; DISKPART needs local administrator rights.

  1. Close the current window.
  2. Select Start, type cmd and select Run as administrator.
  3. Choose Yes at the prompt, then type diskpart again.

Cannot delete a partition or volume

DISKPART blocks the system, boot, paging-file and crash-dump partitions, and non-data partitions without override.

  1. Run detail partition to see the partition type.
  2. Stop if it is the Windows, boot or EFI partition; deleting it leaves the PC unbootable.
  3. For a known data partition of another type, run delete partition override.

Extend fails or the option is unavailable

On a basic disk the free space must sit right after the volume on the same disk, and the volume must be NTFS or unformatted.

  1. Run list partition and check that unallocated space follows the target partition.
  2. Move or delete the partition that sits in between, after backing it up.
  3. Select the volume again and run extend.

Shrink returns zero or fails

Shrink works only on NTFS or unformatted volumes and never on OEM, EFI or recovery partitions.

  1. Run filesystems to confirm the volume is NTFS.
  2. Run shrink querymax to read the largest possible reduction.
  3. Use a desired= value at or below that number.

convert gpt says the disk is not empty

Conversion to GPT requires a disk with no partitions or volumes.

  1. Back up anything on the disk.
  2. Run clean on the selected disk.
  3. Run convert gpt again.

The disk is write-protected or online disk fails

The read-only attribute is set, and online disk fails on a read-only disk.

  1. Select the disk and run attributes disk to view its flags.
  2. Run attributes disk clear readonly.
  3. Run online disk to bring it online.

assign reports the drive letter is in use

Another volume already holds that letter.

  1. Run list volume to find which volume has the letter.
  2. Pick a free letter, for example assign letter=r, or run assign alone for the next free one.

If the file system itself is damaged rather than the partition layout, run a disk check instead; see all chkdsk commands and how to use them.

Final Tips and Best Practices

Use DISKPART when Disk Management cannot do the job, such as cleaning a stubborn USB drive, converting a disk to GPT or scripting a layout, and always run list disk before select disk. DISKPART acts on whatever has focus with no confirmation and no undo, so the only safeguard is checking the target before each destructive command.

Frequently Asked Questions

What is the DISKPART command used for?

DISKPART manages disks, partitions, volumes and virtual hard disks from the command line. It creates, deletes, formats, shrinks and extends partitions, assigns drive letters, converts disks between MBR and GPT, and wipes disks with the clean command.

How do I run DISKPART in Command Prompt?

Open Command Prompt as administrator, type diskpart and press Enter. The prompt changes to DISKPART>, and every command you type after that goes to DISKPART until you type exit. A normal, non-elevated Command Prompt cannot run it.

How do I use DISKPART commands in Windows 10?

The commands are identical in Windows 10 and Windows 11. Start with list disk, select the target with select disk and a number, then run the action, such as clean, create partition primary, format fs=ntfs quick or assign.

What is the command for DISKPART?

The command is simply diskpart, typed at an elevated prompt. To run a prepared file of commands instead of typing them, use diskpart /s followed by the script file name, for example diskpart /s layout.txt.

Which DISKPART command shows all disks?

Type list disk. It shows each disk number, status, size, free space, whether the disk is dynamic, and whether it uses GPT. Use list volume to see drive letters and file systems across all disks.

Does DISKPART clean delete all data?

The clean command removes the partition table, so files become unreachable, but it does not overwrite them. clean all writes zeros to every sector, which deletes the data completely and takes much longer on large drives.

Can DISKPART delete the C drive partition?

No. DISKPART refuses to delete the system partition, the boot partition, and any partition holding the active paging file or crash dump information while Windows is running from it.

Is DISKPART safe to use?

It is safe when you select the correct object. DISKPART never asks for confirmation, so a wrong disk number wipes the wrong drive. Run list disk, match the size, and back up data before clean, delete or convert.

Philip Celasco

Philip is a Texas-based technology writer and IT administrator at Techdows.com with more than 10 years of experience creating practical content for everyday users and professionals. He specializes in web browsers, particularly Chromium-based platforms such as Google Chrome, Microsoft Edge, Brave, and Opera. Through his work as an IT administrator, Philip has hands-on experience managing devices, configuring browser policies, troubleshooting software and network issues, and helping people resolve problems that affect productivity and security. His articles are based on practical testing and real-world technical experience. He covers browser settings, extensions, performance problems, privacy controls, security features, and Windows troubleshooting. Outside work, Philip enjoys the quieter side of life in Texas and stepping away from the screen when he can. He has two kids, two cats and loves to play golf with his mother during the weekends.

Leave a Reply

Your email address will not be published. Required fields are marked *