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 diskpart cheat sheet puts the diskpart commands you’ll actually use in one table set at the top, from create partition primary and a quick NTFS format to cleaning a USB drive, with a one-page PDF you can print. Below them, each step shows its real output, PowerShell twin and errors. Every output comes from two lab VMs, each with a blank 20 GB data disk and an 8 GB disk standing in for a USB stick: Windows 11 24H2, run in October 2026, and Windows Server 2025, run in November 2026.
diskpart Commands Cheat Sheet
Every diskpart command acts on the disk, partition or volume that has focus, so the order is always the same: list, select, then act. Open Terminal (Admin) from the Win + X menu or an administrator Command Prompt, type diskpart, and run these at the DISKPART> prompt. Sizes are in megabytes. Many of the Command Prompt commands used here, from diskpart to netsh, are also on the one-page Windows CMD commands cheat sheet PDF.
Inspect disks, partitions and volumes
| Command | What it does |
|---|---|
list disk | Every disk with number, size, free space and a * in the Gpt column |
list volume | Every volume with letter, label, file system and size |
list partition | Partitions on the selected disk, * marks the one with focus |
detail disk | Type, read-only state and whether it is the boot or pagefile disk |
detail partition | Partition type ID, hidden and active flags, offset |
san | SAN policy that decides if new disks start offline |
Select the target
| Command | What it does |
|---|---|
select disk 1 | Focus on disk 1; check the number with list disk first |
select partition 3 | Focus on partition 3 of the selected disk |
select volume F | Focus on a volume by letter or volume number |
Online, wipe and set GPT or MBR
| Command | What it does |
|---|---|
online disk | Bring a disk online that the SAN policy left offline |
offline disk | Take the selected disk offline, volumes disappear |
clean | Erase the partition table of the selected disk, no prompt |
convert gpt | Empty disk to GPT; adds a Microsoft Reserved partition |
convert mbr | Empty disk to MBR, for sticks that boot BIOS machines |
attributes disk | Show the read-only flag of the selected disk |
attributes disk clear readonly | Clear the flag behind “media is write protected” |
attributes disk set readonly | Make the selected disk read-only |
Create, format and assign
| Command | What it does |
|---|---|
create partition primary size=10240 | 10 GB partition; focus moves to it |
create partition primary | Partition over all remaining free space |
format fs=ntfs quick label=Data | Quick NTFS format with a volume label |
format fs=fat32 quick label=WINUSB | Quick FAT32 format for a boot stick |
format fs=ntfs label=Backup override | Full format past the BitLocker warning |
assign letter=F | Give the volume drive letter F |
active | Mark an MBR partition active for BIOS boot |
Shrink, delete, extend and script
| Command | What it does |
|---|---|
shrink querymax | Show how many MB the selected volume can give up |
shrink desired=2048 | Shrink the selected volume by 2 GB |
delete partition | Remove the selected partition |
delete partition override | Delete a BitLocker or protected partition anyway |
extend size=1024 | Grow the selected volume by 1 GB of the free space after it |
extend | Grow the selected volume into all free space right after it |
diskpart /s C:\lab\data-disk.txt | Run a script file, one command per line |
convert gpt noerr | In a script, carry on past this command’s error |
Every command above was run on the lab VMs (the script rows come from the lab’s own script files), and the sections below show what each one printed. The broader set of Command Prompt tools (netsh, ipconfig, sfc) lives in our Windows CMD commands cheat sheet.
diskpart commands and their PowerShell equivalents
The Storage module in PowerShell covers the same jobs with objects you can filter, which matters in scripts. This table pairs the main diskpart commands with the cmdlet that does the same work:
| 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 |
online disk / offline disk | Brings the selected disk online or takes it offline | Set-Disk -Number 1 -IsOffline $false (or $true) |
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 -Size with the SizeMax value |
shrink querymax | Reports how far the volume can shrink | Get-PartitionSupportedSize (its SizeMin) |
shrink desired=2048 | Shrinks the selected volume by 2048 MB | Resize-Partition -Size with the new, smaller total |
active | Marks an MBR partition active | Set-Partition -IsActive $true |
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 |
The cmdlets live in separate parameter sets, so Set-Disk changes either the read-only flag or the partition style in one call, never both. The PowerShell section below runs the main ones against the same lab disk.
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 Windows 11 lab VM, disk 0 is the 64 GB system disk, and the asterisk in the Gpt column marks it as GPT. 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.
Bring an offline disk online on Windows Server
Add the same two blank disks to Windows Server 2025 and list disk tells a different story. Both spare disks show up as Offline, and nothing you create on them will work until they are online:
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 64 GB 1024 KB *
Disk 1 Offline 20 GB 20 GB
Disk 2 Offline 8 GB 8 GB
detail disk on disk 1 names the reason. The status reads “Offline (Policy)”, and the disk is read-only as well:
QEMU QEMU HARDDISK SCSI Disk Device
Disk ID: 00000000
Type : SAS
Status : Offline (Policy)
Path : 0
Target : 0
LUN ID : 1
Location Path : PCIROOT(0)#PCI(1E00)#PCI(0400)#PCI(0200)#SAS(P00T00L01)
Current Read-only State : Yes
Read-only : Yes
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No
There are no volumes.
The policy in question is the SAN policy, and the san command prints it with no disk selected:
DISKPART> san
SAN Policy : Offline Shared
Microsoft’s san reference says Offline Shared brings new disks online only when they don’t sit on a shared bus such as SCSI or iSCSI, and leaves the rest offline and read-only. Our virtual disks hung off a SCSI controller that reports itself as SAS, so they stayed down, and an iSCSI LUN or a SAS shelf gets the same treatment. The default exists so two servers never write to the same shared disk by accident. Select the disk and bring it online:
DISKPART> select disk 1
Disk 1 is now the selected disk.
DISKPART> online disk
DiskPart successfully onlined the selected disk.
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 64 GB 1024 KB *
* Disk 1 Online 20 GB 20 GB
Disk 2 Offline 8 GB 8 GB
Online is only half of it. attributes disk straight afterwards still showed “Read-only : Yes”, so the read-only flag has to be cleared on its own:
DISKPART> attributes disk clear readonly
Disk attributes cleared successfully.
DISKPART> attributes disk
Current Read-only State : No
Read-only : No
Boot Disk : No
Pagefile Disk : No
Hibernation File Disk : No
Crashdump Disk : No
Clustered Disk : No
offline disk does the reverse, which is handy before you pull a disk or hand it to another host. It printed “DiskPart successfully offlined the selected disk.” and list disk showed “* Disk 1 Offline” until the next online disk. In PowerShell the pair is Set-Disk -Number 1 -IsOffline $false followed by Set-Disk -Number 1 -IsReadOnly $false, because one Set-Disk call changes only one of the two.
On new Server storage, the order that worked on both disks was:
- Run
santo see the policy - Run
select disk 1, thenonline disk - Run
attributes disk clear readonly - Confirm
attributes diskreads No twice
Here is the whole fix in one view, condensed from the Server 2025 run to the lines that matter:

With both disks online and writable, the rest of this guide works the same on Server as on Windows 11.
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. People often search for this step as “diskpart format ntfs quick”, but the file system needs its fs= key, so the working line is format fs=ntfs quick:
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 Windows 11 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 9.98 GB G: 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. With no key protector involved, adding override to the command lets it through and only removes encryption you never activated.
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, saving the printed key, then checkmanage-bde -status F:
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. Automatic unlock with manage-bde -autounlock -enable F: only works once C: itself is BitLocker-protected, per Microsoft’s BitLocker FAQ. On our lab VM C: had no key protector yet, so F: would have asked for its 48-digit password after every reboot.
Shrink a volume with shrink querymax and desired
Shrinking frees space at the end of a volume without touching its data, and it only works on NTFS or unformatted volumes. Ask diskpart how far it can go before you pick a number. On the Server 2025 VM, F: was the 10 GB Data volume built with the same create, format and assign lines shown above:
DISKPART> select volume F
Volume 4 is the selected volume.
DISKPART> shrink querymax
The maximum number of reclaimable bytes is: 7117 MB
Despite the word “bytes”, the figure is in megabytes, like every size diskpart takes. shrink desired= takes the amount to remove, not the size you want to end up with, so 2048 cuts 2 GB off the volume:
DISKPART> shrink desired=2048
DiskPart successfully shrunk the volume by: 2048 MB
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Reserved 15 MB 17 KB
* Partition 2 Primary 8 GB 16 MB
Partition 3 Primary 9 GB 10 GB
That took 8.8 seconds on an empty volume. Files that can’t be moved, such as a pagefile, cap how far a busy volume shrinks, and querymax already accounts for them. The freed 2 GB now lies between partitions 2 and 3, and extend size=1024 hands half of it back:
DISKPART> extend size=1024
DiskPart successfully extended the volume.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Reserved 15 MB 17 KB
* Partition 2 Primary 9 GB 16 MB
Partition 3 Primary 9 GB 10 GB
A bare extend right after took the last 1 GB and put partition 2 back at 10 GB, which closes the round trip shown here:

The PowerShell route asks the same question with Get-PartitionSupportedSize, whose SizeMin is the smallest size the partition can shrink to, and then sets an absolute size with Resize-Partition. Both appear in the PowerShell section with real output.
Delete a partition and extend the volume
Deleting works like creating: select the disk, select the partition, run delete partition. On the Windows 11 VM the BitLocker check stopped it the same way it stopped the format, so the working version below carries override. The Windows Server 2025 VM had no encryption running on its data disk, and there plain delete partition printed “DiskPart successfully deleted the selected partition.” on the first try. 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, and per Microsoft’s extend reference it fails on a partition formatted with anything other than NTFS, so it won’t grow the FAT32 stick below. On a system disk with a recovery partition behind C:, it fails until that partition is moved or removed, a trap Markus Elsberger’s diskpart walkthrough on it-learner.de (German) also flags. 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
A diskpart clean USB run is the fix people reach 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
The whole script, with three list and detail commands after these seven, finished in 1.05 seconds on Windows 11. 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. 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. If the stick you are cleaning is an old USB 2.0 one, a USB 3 drive such as the SanDisk 128GB Ultra Flair plugged into a USB 3 port writes an install image much faster than a USB 2.0 stick, and the same clean sequence prepares it. 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
If you wrap diskpart in a batch file, the one-page Windows CMD commands cheat sheet covers the surrounding Command Prompt syntax.
diskpart reads commands from a text file with /s, which is how every transcript in this guide was produced on the lab VMs. 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. To see both sides, we pointed this three-line script at the 8 GB disk, which still held the FAT32 partition from the USB test:
select disk 2
convert gpt
list partition
convert gpt fails on a disk that isn’t empty, so diskpart printed the error and quit. list partition never ran, and the exit code PowerShell read from $LASTEXITCODE was -2147211943:
Disk 2 is now the selected disk.
Virtual Disk Service error:
The specified disk is not convertible. CDROMs and DVDs
are examples of disks that are not convertable.
Change the second line to convert gpt noerr and run it again. The same error prints, but diskpart carries on to the next line and exits with 0:
Disk 2 is now the selected disk.
Virtual Disk Service error:
The specified disk is not convertible. CDROMs and DVDs
are examples of disks that are not convertable.
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 8190 MB 1024 KB
Here are both runs back to back in the Server 2025 console. The only difference between the two script files is the noerr on the convert line:

Stopping is usually what you want. On the Windows 11 VM, a script whose delete partition hit the BitLocker check ended there instead of going on to extend the wrong layout. Keep noerr for lines that are allowed to fail, such as online disk noerr on a disk that may already be online, and check the exit code in the calling batch file. 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 Number, FriendlyName, PartitionStyle, OperationalStatus, Size -AutoSize
On the Server 2025 VM, disk 2 still had the MBR layout from the USB test. Size comes back in bytes:
Number FriendlyName PartitionStyle OperationalStatus Size
------ ------------ -------------- ----------------- ----
0 QEMU QEMU HARDDISK GPT Online 68719476736
1 QEMU QEMU HARDDISK GPT Online 21474836480
2 QEMU QEMU HARDDISK MBR Online 8589934592
On the Windows 11 VM, the next three lines replaced 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. -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
On the Windows 11 VM, Get-Partition -DiskNumber 2 afterwards listed a Microsoft Reserved partition ahead of the new volume, the same MSR that convert gpt adds in diskpart. 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.
We ran the rest of the pairs on the Server 2025 VM, again against disk 2. Taking a disk offline is one parameter, and Get-Disk confirms it:
Set-Disk -Number 2 -IsOffline $true; Get-Disk -Number 2 | Format-Table Number, OperationalStatus, IsReadOnly -AutoSize
Unlike the SAN policy, a manual offline leaves the read-only flag alone:
Number OperationalStatus IsReadOnly
------ ----------------- ----------
2 Offline False
For the shrink pair we cleared the disk, initialized it as MBR and created a 4 GB NTFS volume on V: with New-Partition -DiskNumber 2 -Size 4GB -DriveLetter V piped to Format-Volume, then asked how far it could move:
Get-PartitionSupportedSize -DriveLetter V | Format-List
The two values are byte counts, roughly 1.05 GB and 8 GB here. Any size between them is valid:
SizeMin : 1126436864
SizeMax : 8587837440
Resize-Partition takes the target size, so shrinking V: from 4 GB to 3 GB is -Size 3GB, where diskpart would need shrink desired=1024. The two Set-Partition lines swap the letter and set the active flag, the cmdlet versions of assign letter= and active:
Resize-Partition -DriveLetter V -Size 3GB
Set-Partition -DriveLetter V -NewDriveLetter W
Set-Partition -DiskNumber 2 -PartitionNumber 1 -IsActive $true
Get-Partition -DiskNumber 2 | Format-Table PartitionNumber, DriveLetter, Size, IsActive -AutoSize
The partition came back at exactly 3 GB (3221225472 bytes) under its new letter, marked active:
PartitionNumber DriveLetter Size IsActive
--------------- ----------- ---- --------
1 W 3221225472 True
The whole sequence on Server 2025, from the size query to the active flag, looked like this in the console:

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 one of the two lab VMs, with the cause and the fix that worked there. Three of them came from short diskpart scripts on Server 2025: a create with nothing selected, a clean on the boot disk, and active on a GPT disk.

Those three have headings of their own below, alongside the write-protect, convert and override messages.
“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 writes such as clean. On the Windows 11 VM we set one with attributes disk set readonly on the 8 GB disk, which still held a partition, and the next clean printed this error. The same test on Windows Server 2025 went the other way: the 20 GB disk had never been initialized, and clean reported “DiskPart succeeded in cleaning the disk.” right after the flag was set. So a successful clean doesn’t prove the flag is gone. 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. On Windows Server, a disk that the SAN policy kept offline stays read-only after online disk, so run attributes disk on new server storage before you partition it. 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.
“The ACTIVE command can only be used on fixed MBR disks”
We ran active against partition 2 of the GPT data disk on Server 2025, and diskpart refused with “The selected disk is not a fixed MBR disk.” followed by this line. GPT disks have no active flag, because UEFI firmware boots from the EFI system partition instead. If the drive really has to boot a BIOS machine, empty it with clean, run convert mbr and then mark the new partition active, as in the USB section.
“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.
Most of these errors trace back to the same habit: running a command before checking which disk or volume has focus. Keep list disk and detail disk as the first two lines of every session, and the rest of this sheet stays safe to paste. When the stick you just cleaned is headed for a Linux install, our guide to writing a Windows bootable USB from Linux covers the other direction.
hi
how we can do this for mbr disk?
Thank you for the info. Very helpful