The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| Open DiskPart | diskpart | View examples |
| Show launcher help | diskpart /? | View examples |
| List command help | help | View examples |
| Explain one command | help select disk | View examples |
| List disks | list disk | View examples |
| List volumes | list volume | View examples |
| List selected disk partitions | list partition | View examples |
| List virtual disks | list vdisk | View examples |
| Select a disk | select disk 3 | View examples |
| Select a volume | select volume 7 | View examples |
| Verify selected disk | detail disk | View examples |
| Verify selected volume | detail volume | View examples |
| Rescan storage | rescan | View examples |
| Add a script comment | rem Verify the approved disk before continuing | View examples |
| Run a script | diskpart /s C:\Admin\disk-audit.txt | View examples |
| Capture script output | diskpart /s C:\Admin\disk-audit.txt > `
C:\Admin\disk-audit.log | View examples |
| Exit DiskPart | exit | View 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
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.
diskpart
help
help select disk
help detail disk 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.
list disk
list volume
list vdisk
rescan
list disk 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.
list disk
select disk 3
detail disk
list partition
list volume
select volume 7
detail volume 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.
list disk
select disk 3
detail disk
list partition
list volume
rem Stop if size, model, unique ID, or layout is unexpected. 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.
rem disk-audit.txt
list disk
list volume
list vdisk
exit diskpart /s C:\Admin\disk-audit.txt > C:\Admin\disk-audit.log 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.
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" } Sources and further reading
References
Authoritative documentation used to verify and expand this cheat sheet.
Help us improve
Found a typo or missing example?
Tell us what would make this cheat sheet clearer, more complete, or more useful.



