The essentials
Quick reference
One focused task per row. Jump to the related section for complete, working examples.
| Use | Syntax | Examples |
|---|---|---|
| Create an expandable VHDX | create vdisk file="C:\VHDs\Data.vhdx" maximum=65536 `
type=expandable | View examples |
| Create a fixed VHDX | create vdisk file="C:\VHDs\Fixed.vhdx" maximum=65536 `
type=fixed | View examples |
| Create a differencing child | create vdisk file="C:\VHDs\Lab-child.vhdx" `
parent="C:\VHDs\Lab-base.vhdx" | View examples |
| Create a VHD copy | create vdisk file="C:\VHDs\Data-copy.vhdx" `
source="C:\VHDs\Data.vhdx" | View examples |
| Select a virtual disk file | select vdisk file="C:\VHDs\Data.vhdx" | View examples |
| Inspect the selected VHD | detail vdisk | View examples |
| List virtual disks | list vdisk | View examples |
| Attach read-only | attach vdisk readonly | View examples |
| Attach read-write | attach vdisk | View examples |
| Detach the virtual disk | detach vdisk | View examples |
| Compact an expandable VHD | compact vdisk | View examples |
| Expand virtual capacity | expand vdisk maximum=131072 | View examples |
| Merge one parent level | merge vdisk depth=1 | View examples |
| Find the attached disk | list disk | View examples |
| Verify attached disk identity | detail disk | View examples |
| Exit DiskPart | exit | View 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
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.
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 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.
list vdisk
select vdisk file="C:\VHDs\Data.vhdx"
detail vdisk 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.
select vdisk file="C:\VHDs\Data.vhdx"
attach vdisk readonly
detail vdisk
list disk
list volume
detach vdisk 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.
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. 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.
select vdisk file="C:\VHDs\Data.vhdx"
detail vdisk
detach vdisk
expand vdisk maximum=131072
detail vdisk 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.
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 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.



