The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
Open DiskPartdiskpartView examples
Show launcher helpdiskpart /?View examples
List command helphelpView examples
Explain one commandhelp select diskView examples
List diskslist diskView examples
List volumeslist volumeView examples
List selected disk partitionslist partitionView examples
List virtual diskslist vdiskView examples
Select a diskselect disk 3View examples
Select a volumeselect volume 7View examples
Verify selected diskdetail diskView examples
Verify selected volumedetail volumeView examples
Rescan storagerescanView examples
Add a script commentrem Verify the approved disk before continuingView examples
Run a scriptdiskpart /s C:\Admin\disk-audit.txtView examples
Capture script outputdiskpart /s C:\Admin\disk-audit.txt > ` C:\Admin\disk-audit.logView examples
Exit DiskPartexitView examples

DiskPart is an administrative command interpreter for disks, partitions, volumes, and virtual disks. Its most important concept is focus: most commands act on the currently selected object, and that selection persists until another command changes it. Inventory first, select explicitly, verify with detail, and keep destructive commands out of reusable scripts until the target identity is independently approved.

Step by step

Detailed examples

01

Start elevated and use local help

DiskPart requires local administrator or equivalent permissions. Start it from an elevated Command Prompt or PowerShell window. The installed help is valuable because command availability and behavior can vary by Windows release; read help before using an unfamiliar switch.

Start and inspect command syntax
diskpart
help
help select disk
help detail disk
Back to quick reference ↑
02

Inventory every storage layer

A disk contains partitions, a partition can expose a volume, and a VHD can surface as another disk. Run list commands before selection. List partition depends on the selected disk, while list disk and list volume are system-wide. Rescan only refreshes discovery; it does not prove that a newly numbered disk is the device you intended.

Read-only storage inventory
list disk
list volume
list vdisk
rescan
list disk
Back to quick reference ↑
03

Understand persistent and changing focus

Selection persists. Selecting a volume can shift focus to its related disk and partition when the mapping is unambiguous, and creating an object automatically focuses the new object. Never rely on a selection made many commands earlier. Repeat select and detail immediately before a state-changing command.

Trace disk and volume focus
list disk
select disk 3
detail disk
list partition
list volume
select volume 7
detail volume
Back to quick reference ↑
04

Verify identity instead of trusting a number

Disk numbers and volume numbers can change after reboot, hot-plug, imaging, or controller changes. Match several facts: size, model, location path, unique ID, partition layout, labels, and expected volumes. If any fact disagrees, stop. On multi-disk deployments, hardware location paths are safer than assuming disk 0.

Independent identity check
list disk
select disk 3
detail disk
list partition
list volume
rem Stop if size, model, unique ID, or layout is unexpected.
Back to quick reference ↑
05

Keep scripts simple and reviewable

A DiskPart script is plain text with one command per line and no empty lines. Use rem for comments. DiskPart has no variables, loops, conditions, transactions, WhatIf, or confirmation framework, so generate target-specific scripts only after external validation. Keep discovery scripts separate from approved destructive scripts.

Safe inventory script content
rem disk-audit.txt
list disk
list volume
list vdisk
exit
Run the inventory script
diskpart /s C:\Admin\disk-audit.txt > C:\Admin\disk-audit.log
Back to quick reference ↑
06

Fail closed and preserve evidence

By default, a DiskPart script stops when an operational command fails. The noerr parameter can continue after some errors and should be rare because later commands may act on an unexpected focus or layout. Syntax errors still fail. Microsoft also advises allowing at least 15 seconds between consecutive DiskPart scripts; one coherent script is usually easier to audit.

Run, log, and inspect the result
diskpart /s C:\Admin\disk-audit.txt > C:\Admin\disk-audit.log
Get-Content C:\Admin\disk-audit.log
if ($LASTEXITCODE -ne 0) { throw "DiskPart failed with exit code $LASTEXITCODE" }
Back to quick reference ↑

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. Microsoftdiskpartlearn.microsoft.com
  2. Microsoftdiskpart scripts and exampleslearn.microsoft.com
  3. Microsoftselect disklearn.microsoft.com
  4. MicrosoftConfigure multiple hard driveslearn.microsoft.com

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback