The essentials

Quick reference

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

UseSyntaxExamples
Create an expandable VHDXcreate vdisk file="C:\VHDs\Data.vhdx" maximum=65536 ` type=expandableView examples
Create a fixed VHDXcreate vdisk file="C:\VHDs\Fixed.vhdx" maximum=65536 ` type=fixedView examples
Create a differencing childcreate vdisk file="C:\VHDs\Lab-child.vhdx" ` parent="C:\VHDs\Lab-base.vhdx"View examples
Create a VHD copycreate vdisk file="C:\VHDs\Data-copy.vhdx" ` source="C:\VHDs\Data.vhdx"View examples
Select a virtual disk fileselect vdisk file="C:\VHDs\Data.vhdx"View examples
Inspect the selected VHDdetail vdiskView examples
List virtual diskslist vdiskView examples
Attach read-onlyattach vdisk readonlyView examples
Attach read-writeattach vdiskView examples
Detach the virtual diskdetach vdiskView examples
Compact an expandable VHDcompact vdiskView examples
Expand virtual capacityexpand vdisk maximum=131072View examples
Merge one parent levelmerge vdisk depth=1View examples
Find the attached disklist diskView examples
Verify attached disk identitydetail diskView examples
Exit DiskPartexitView examples

DiskPart can surface a virtual hard disk as a local disk and manage common VHD or VHDX lifecycle operations. The file path becomes part of the virtual disk's identity, while the attached disk receives a normal disk number that can change. Protect host capacity, verify file and parent-chain identity, attach unknown images read-only first, and detach a virtual disk before copying, expanding, or merging it.

Step by step

Detailed examples

01

Choose fixed, expandable, copy, or differencing behavior

Fixed files reserve their full capacity immediately and take longer to create. Expandable files grow as blocks are written but can exhaust host storage before reaching their virtual maximum. Source creates an independent copy; parent creates a dependent differencing disk. Ensure the destination directory exists, has sufficient capacity, and is protected by appropriate ACLs and backup policy.

Create a 64 GB expandable VHDX
New-Item -ItemType Directory -Path C:\VHDs -Force
Get-Volume -DriveLetter C | Format-Table DriveLetter, Size, SizeRemaining
diskpart
create vdisk file="C:\VHDs\Data.vhdx" maximum=65536 type=expandable
detail vdisk
Back to quick reference ↑
02

Select by canonical file path and inspect details

Select vdisk uses the file path, which is safer than relying on an attached disk number. Detail vdisk reports the virtual disk's type, state, capacity, and associated disk. Verify the resolved path, expected size, attachment state, and parent information before every write operation.

Read-only virtual disk inventory
list vdisk
select vdisk file="C:\VHDs\Data.vhdx"
detail vdisk
Back to quick reference ↑
03

Attach unknown images read-only first

Attaching surfaces the VHD as a normal local disk and can trigger automount and application discovery. Read-only attachment limits writes but does not make untrusted contents safe to execute. Before detach, close files, stop consumers, flush application data, and verify no process is using the mounted volume. Detach before moving or copying the file.

Inspect a VHD without modifying it
select vdisk file="C:\VHDs\Data.vhdx"
attach vdisk readonly
detail vdisk
list disk
list volume
detach vdisk
Back to quick reference ↑
04

Treat an attached VHD like any other disk

A newly created VHD is uninitialized. After attachment, list disks and prove which new disk maps to the VHD using detail vdisk and detail disk. Never assume a fixed disk number. Partitioning and formatting the attached disk are destructive inside the image, and selecting the wrong disk can damage the host.

Verify before initializing a new virtual disk
select vdisk file="C:\VHDs\Data.vhdx"
attach vdisk
list disk
detail vdisk
rem Note the associated disk number, select it explicitly, then run detail disk.
rem Initialize only after both detail views identify Data.vhdx.
Back to quick reference ↑
05

Distinguish file size, virtual disk, partition, and filesystem

Compact reduces physical file usage only for dynamically expanding VHDs that are detached or attached read-only; deleted guest blocks may need optimization before compaction can reclaim them. Expand raises virtual capacity and requires the VHD to be detached, but does not extend partitions or filesystems inside it. Verify host free space before either operation and grow internal layers separately.

Expand a detached VHDX to 128 GB
select vdisk file="C:\VHDs\Data.vhdx"
detail vdisk
detach vdisk
expand vdisk maximum=131072
detail vdisk
Back to quick reference ↑
06

Protect every differencing-disk dependency

A differencing child depends on the exact parent content and path chain. Do not edit, rename, move, compact, or replace a parent without understanding every descendant. Merge modifies the parent and Microsoft warns that other children depending on that parent can become invalid. Shut down workloads, detach the chain, inventory descendants, and back up every layer before merge.

Review a child before a one-level merge
select vdisk file="C:\VHDs\Lab-child.vhdx"
detail vdisk
rem Verify the parent and every sibling child; stop all consumers and back up the chain.
rem Destructive to chain state: merge vdisk depth=1
Back to quick reference ↑

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. Microsoftdiskpartlearn.microsoft.com
  2. Microsoftattach vdisklearn.microsoft.com
  3. Microsoftcompact vdisklearn.microsoft.com
  4. Microsoftexpand vdisklearn.microsoft.com
  5. Microsoftmerge vdisklearn.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