The diskpart create partition command takes about a second to run. What takes care is the line before it, select disk, because diskpart acts on whatever disk has focus and it never asks “are you sure?” when you run clean or delete. Pick the wrong number and you’ve wiped a drive in less time than it took to type the command.
This guide covers the diskpart commands you’ll actually use, from create partition primary and a quick NTFS format to cleaning a USB drive. Each step gets its PowerShell equivalent, and the errors diskpart printed are indexed at the end. Every command shown with its output below was run on Windows 11 24H2 in October 2026, on a lab VM with a blank 20 GB data disk and an 8 GB disk standing in for a USB stick.
diskpart commands at a glance
Most jobs need fewer than ten commands. The table pairs each one with what it does and the PowerShell cmdlet that does the same job, so you can pick whichever tool fits the script you’re writing:
| diskpart command | What it does | PowerShell equivalent |
|---|---|---|
list disk | Shows every disk with its number, size, free space and GPT flag | Get-Disk |
select disk 1 | Puts focus on disk 1; every later command acts on it | -Number 1 (disk cmdlets) or -DiskNumber 1 (partition cmdlets) |
detail disk | Shows whether the disk holds the boot, system or pagefile volume | Get-Disk -Number 1 | Format-List |
convert gpt / convert mbr | Sets the partition style on an empty disk | Initialize-Disk -PartitionStyle GPT on a RAW disk, Set-Disk -PartitionStyle GPT on an initialized empty one |
create partition primary size=10240 | Creates a 10 GB partition (size is in MB; leave it out to use all free space) | New-Partition -Size 10GB |
format fs=ntfs quick label=Data | Quick-formats the selected partition as NTFS | Format-Volume -FileSystem NTFS |
assign letter=F | Gives the volume a drive letter | Set-Partition -NewDriveLetter F |
delete partition | Removes the selected partition | Remove-Partition |
extend | Grows the selected volume into free space that follows it | Resize-Partition |
clean | Wipes the partition table of the selected disk | Clear-Disk -RemoveData |
attributes disk clear readonly | Removes a read-only flag that blocks writes | Set-Disk -IsReadOnly $false |
Every one of these needs an elevated prompt. Open Terminal (Admin) from the Win + X menu, or an administrator Command Prompt, and type diskpart. On Windows Server the same steps work from an elevated PowerShell window.
Find the right disk before you touch it
Start every session with list disk, because disk numbers are not stable. They follow controller order, so a USB stick that was disk 2 yesterday can be disk 1 today if you unplugged something else. Size is usually the quickest way to tell disks apart.
list disk
On the lab VM, disk 0 is the 64 GB system disk (the asterisk in the Gpt column marks it as GPT), while disks 1 and 2 are blank, which is why their free space equals their size:
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 64 GB 1024 KB *
Disk 1 Online 20 GB 20 GB
Disk 2 Online 8 GB 8 GB
Select the disk, then run detail disk before anything destructive. It costs one line and tells you whether the disk carries the boot, pagefile or hibernation file, which is the disk you never want to clean. A blank data disk answers “No” to all of them and “There are no volumes”:
DISKPART> select disk 1
Disk 1 is now the selected disk.
DISKPART> detail disk
QEMU HARDDISK
Disk ID: 00000000
Type : SATA
Status : Online
Path : 2
Target : 0
LUN ID : 0
Location Path : PCIROOT(0)#PCI(1E00)#PCI(0100)#PCI(0700)#ATA(C02T00L00)
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No
There are no volumes.
Disk ID 00000000 is another hint the disk has never been initialized. Any disk you plan to partition from scratch should look like this one before you go further.
Set the partition style to GPT or MBR
Pick GPT for any internal data disk and anything larger than 2 TB. MBR is only worth choosing for a USB stick that has to boot older BIOS machines, and that case is covered in the USB section below. The conversion only works on an empty disk.
DISKPART> convert gpt
DiskPart successfully converted the selected disk to GPT format.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Reserved 15 MB 17 KB
That 15 MB Reserved partition was not created by hand. convert gpt adds the Microsoft Reserved partition (MSR) on its own, so the first partition you create will be number 2, not 1. Keep that in mind when you select partition later, because selecting partition 1 on a GPT data disk selects the MSR.
diskpart create partition, format and assign a letter
Creating a usable volume is always the same three commands: create partition primary, format and assign. After create, focus moves to the new partition on its own, so you don’t need a select partition between them. The size value is in megabytes (the create partition primary reference lists the other options), which is why 10 GB is written as 10240:
create partition primary size=10240
format fs=ntfs quick label=Data
assign letter=F
For the second partition we left size out, so diskpart used the rest of the free space. Then list partition and list volume confirm what was built. The asterisk marks the partition and volume that currently have focus.
DISKPART> create partition primary
DiskPart succeeded in creating the specified partition.
DISKPART> format fs=ntfs quick label=Backup
0 percent completed
0 percent completed
0 percent completed
0 percent completed
0 percent completed
100 percent completed
DiskPart successfully formatted the volume.
DISKPART> assign letter=G
DiskPart successfully assigned the drive letter or mount point.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Reserved 15 MB 17 KB
Partition 2 Primary 10 GB 16 MB
* Partition 3 Primary 9 GB 10 GB
DISKPART> list volume
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 D UNATTEND CDFS CD-ROM 368 KB Healthy
Volume 1 E CFGPST CDFS CD-ROM 125 MB Healthy
Volume 2 C Windows NTFS Partition 62 GB Healthy Boot
Volume 3 SYSTEM FAT32 Partition 300 MB Healthy System
Volume 4 NTFS Partition 888 MB Healthy Hidden
Volume 5 F Data NTFS Partition 10 GB Healthy
* Volume 6 G Backup NTFS Partition 9 GB Healthy
D and E were already taken by two CD-ROM drives on this VM, which is why the new volumes went to F and G. If you skip assign, automount (on by default in Windows 11) usually hands out the next free letter, but scripts and backup jobs that expect a fixed path should always set one. The capture below shows that session on the lab VM, condensed to the progress line that matters and the volumes this disk added:

The whole sequence, both partitions included, finished in 6.3 seconds.
Quick format or full format?
Use quick on any new or healthy disk. A quick format only writes a fresh file system, while a full format also writes every sector, so its run time grows with the size of the volume. On the lab’s 10 GB volume a full format took 21.3 seconds against a few seconds for the quick one, and on a 4 TB spinning disk the same full format runs for hours. A full format buys you two things: a scan for bad sectors, and zeros over the old data so nobody can recover it later. Keep it for a drive you suspect is failing or one that is leaving your hands.
Why Windows 11 asks for override on a new volume
The first time we ran a full format on G:, diskpart refused, even though the volume had existed for under a minute:
The volume you selected to format is encrypted with BitLocker Drive Encryption.
BitLocker encryption will be removed and the encrypted data on the volume will be erased.
You may enable BitLocker again after formatting is complete.
To proceed with the format, run FORMAT again using the OVERRIDE parameter.
Windows 11 device encryption was on for this install, with C: already encrypted and waiting for a key protector. It started encrypting both new NTFS volumes the moment they were formatted. manage-bde -status G: showed “Encryption in Progress” with XTS-AES 128 and “Protection Off”, which means no key protector exists yet. Nothing is locked, so nothing is lost if you reformat, and adding override to the command lets it through.
format fs=ntfs label=Backup override
Encryption started again right after that format finished, so decide what you want for data disks before you fill them. There are three ways to settle it:
- Device encryption off under Settings > Privacy & security > Device encryption, which decrypts C: as well
manage-bde -off F:to decrypt one data volumemanage-bde -protectors -add F: -RecoveryPasswordto keep it encrypted and save the printed key
On Pro and Enterprise editions the Device encryption page may not appear at all, and the BitLocker control panel or manage-bde does the same job. If you keep encryption, store that recovery password somewhere other than the disk itself, because it is the only way back into the volume when its unlock method stops working.
Delete a partition and extend the volume
Deleting works like creating: select the disk, select the partition, run delete partition. On the lab VM the BitLocker check stopped it the same way it stopped the format, so the working version carries override. Then we selected F: and ran extend with no size, which grows the volume into all the free space directly after it:
DISKPART> select disk 1
Disk 1 is now the selected disk.
DISKPART> select partition 3
Partition 3 is now the selected partition.
DISKPART> delete partition override
DiskPart successfully deleted the selected partition.
DISKPART> select volume F
Volume 5 is the selected volume.
DISKPART> extend
DiskPart successfully extended the volume.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Reserved 15 MB 17 KB
* Partition 2 Primary 19 GB 16 MB
F: went from 10 GB to 19.98 GB without a reboot and without touching its data. extend only reaches unallocated space that sits right after the volume on the same disk. On a system disk with a recovery partition behind C:, it fails until that partition is moved or removed. For a VM disk you grew on the hypervisor, the free space lands at the end, which is the case extend handles best; our guide to growing a KVM virtual machine disk covers the host side.
Use diskpart clean on a USB drive
clean is the command people search for when a USB stick shows the wrong size, has leftover Linux partitions, or won’t format from Explorer. It deletes the partition table of the selected disk in about a second and never asks for confirmation. Before you run it, check three things:
- Run
list diskwith the stick plugged in, and again after unplugging it, to see which number disappears - Match the size column to the stick’s capacity
- Run
detail diskand confirm it shows “Boot Disk : No”
Plain clean only overwrites the partition table (on GPT, the GPT headers and the protective MBR, per Microsoft’s clean reference), so recovery tools can often still find the old files. clean all writes zeros to every sector instead. That is what you want before giving a drive away, but on a large USB 2.0 stick it can run for an hour or more. Windows does give you one safety net: diskpart refuses clean on the disk that holds the running system, as the error index at the end shows. Any other disk, including your backup drive, is fair game.
For a stick that has to boot both UEFI and older BIOS machines, use MBR, mark the partition active, and format it FAT32. In our lab the “USB stick” was an 8 GB virtual disk, so the commands and output are real, but a physical stick reports “Type : USB” in detail disk where ours said SATA. Replace 2 with the number you confirmed for your stick before you paste this:
select disk 2
clean
convert mbr
create partition primary
active
format fs=fat32 quick label=WINUSB
assign letter=U
All seven commands finished in 1.05 seconds. The partition detail confirms type 0C (FAT32 with LBA) and the active flag that BIOS firmware looks for:

FAT32 caps single files at 4 GB. Copying a downloaded Windows ISO onto the stick by hand hits that limit, because its install.wim is larger, so the WIM has to be split or written by a tool that handles it. Our guide to creating a bootable Windows 11 USB walks through both the Media Creation Tool and Rufus. On Linux, the same job is done with parted, as shown in formatting a USB drive from the Linux terminal.
Run diskpart from a script
diskpart reads commands from a text file with /s, which is how every transcript in this guide was produced on the lab VM. That makes partitioning repeatable and reviewable, because you can read the file before it runs. Save the commands one per line, for example as C:\lab\data-disk.txt:
select disk 1
convert gpt
create partition primary size=10240
format fs=ntfs quick label=Data
assign letter=F
Then run it from an elevated prompt.
diskpart /s C:\lab\data-disk.txt
A script stops at the first error unless the failing command carries noerr. That is the behaviour you want, and our delete test showed why: when delete partition hit the BitLocker check, the script ended there instead of going on to extend the wrong layout. Hard-code the disk number only in scripts that run on known hardware; anywhere else, check list disk first or switch to PowerShell, which can select a disk by size or serial number.
Use the PowerShell equivalents
The Storage module does the same work with objects you can filter, so it is the better choice in automation. Start with the disk list, which shows the partition style that diskpart only hints at with an asterisk:
Get-Disk | Format-Table -AutoSize Number,FriendlyName,OperationalStatus,@{n='Size';e={'{0} GB' -f [math]::Round($_.Size/1GB)}},PartitionStyle
Plain Get-Disk works too, but its default columns include serial numbers and health instead. Disk 2 still had the MBR layout from the USB test.
Number FriendlyName OperationalStatus Size PartitionStyle
------ ------------ ----------------- ---- --------------
0 QEMU HARDDISK Online 64 GB GPT
1 QEMU HARDDISK Online 20 GB GPT
2 QEMU HARDDISK Online 8 GB MBR
The next three lines replace clean, convert gpt, create partition primary, format and assign. Clear-Disk wants -RemoveData when the disk has data partitions, and -RemoveOEM when it has OEM ones, and -Confirm:$false skips the prompt, so treat that line with the same care as clean and swap 2 for the disk number Get-Disk showed you:
Clear-Disk -Number 2 -RemoveData -RemoveOEM -Confirm:$false
Initialize-Disk -Number 2 -PartitionStyle GPT
New-Partition -DiskNumber 2 -UseMaximumSize -DriveLetter U | Format-Volume -FileSystem NTFS -NewFileSystemLabel Scratch -Confirm:$false
Format-Volume returns the finished volume, so the pipeline doubles as its own check:
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
U Scratch NTFS Fixed Healthy OK 7.95 GB 7.98 GB
Get-Partition -DiskNumber 2 shows that Initialize-Disk also added the Microsoft Reserved partition, listed as 16 MB, where diskpart showed its own MSR on disk 1 as 15 MB. Where PowerShell pays off is selection: Get-Disk | Where-Object BusType -eq USB picks the stick by bus type instead of by a number that can change, which diskpart has no way to do. If you spend a lot of time in the shell, our list of PowerShell keyboard shortcuts saves a lot of retyping.
Prefer clicking? Disk Management does all of this too, and our look at a better alternative to Disk Management covers a GUI that also moves partitions. A fresh disk is a fresh disk whichever tool you use, from a spare HDD to the NVMe and SATA SSDs we rate for servers.
Fix common diskpart errors
Each message below is verbatim from the lab VM, with the cause and the fix that worked there.
“There is no disk selected to create a partition”
Focus does not survive between diskpart sessions, so a new session or script that starts with create partition primary fails straight away. Run select disk N first. The same rule applies to format, which needs a selected partition or volume.
“Clean is not allowed on the disk containing the current boot, system, pagefile, crashdump or hibernation volume”
This is what you get after select disk 0 and clean on a running system, and it means you picked the system disk. Re-check list disk. If you really mean to wipe that disk, boot from Windows install media, press Shift + F10 at the setup screen and run diskpart there, where the disk is no longer in use.
“The specified disk is not convertible”
The message blames CD-ROMs and DVDs, but on our lab disk the real cause was simpler. The disk still had a partition on it, and convert gpt and convert mbr only work on an empty disk. Run clean on it first, once you’ve confirmed it holds nothing you need.
“DiskPart has encountered an error: The media is write protected”
A read-only attribute on the disk blocks clean, format and create. We set one with attributes disk set readonly to reproduce it, and attributes disk then showed “Read-only : Yes”. Clear it and check that it took.
attributes disk clear readonly
attributes disk
Both “Current Read-only State” and “Read-only” should read No afterwards. If the flag comes back or won’t clear on a USB stick, look for a physical lock switch on the stick or its SD adapter. A stick that still refuses after that is usually failing flash that the controller has locked read-only, and that is the point to retire it for one of the external drives we rate for backups.
“To proceed with the deletion, run DELETE again using the OVERRIDE parameter”
diskpart prints this for a volume that BitLocker has encrypted or is still encrypting, and for format it prints a similar warning that ends with “run FORMAT again using the OVERRIDE parameter”. Run manage-bde -status on the volume first. If it says “Protection Off” with no key protectors, nothing will lock and you can repeat the command with override. If protection is on, make sure you don’t need the data, because the override destroys it along with the encryption.
hi
how we can do this for mbr disk?
Thank you for the info. Very helpful