Is it possible to expand an existing dynamic VHD? I am looking at DiscUtils.Vhd.Disk class but I don't see any methods that would help me. The Capacity property is read-only.
You can do this operation in Hyper-V manager (Edit Disk) and it is instant. So I guess it just bumps the maximum disk size. It does not expand any partitions on the disk, but I don't need that. You can also do this using WMI, here is a little PowerShell
script as example:
$vhdPath = "D:\8328.vhd"
$vhdNewSizeGB = 64
$ImageMgtService = Get-WmiObject -namespace "root\virtualization" -class "Msvm_ImageManagementService"
$ImageMgtService.ExpandVirtualHardDisk($vhdPath, $vhdNewSizeGB * 1024 * 1024 * 1024)