Powershell Resize-VHD is not recognized as the name of a cmdlet
Sebastian Wright
I'm trying to use Resize-VHD cmdlet, but this results in the following error:
PS> Resize-VHD -Path "C:\Container.vhd" -SizeBytes 20GB Error: Resize-VHD : The term 'Resize-VHD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Resize-VHD -Path "C:\Container.vhd" -SizeBytes 20GB + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Resize-VHD:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundExceptionHow do I fix that?
22 Answers
Turns out I needed to install Hyper-V features on Windows (even though I don't need Hyper-V itself, I use VHD as portable file container)
- Go to
Control Panel | Programs and features | Turn windows features on or off - Tick
Hyper-V | Hyper-V Management tools | Hyper-V Module for Windows PowerShell - When installed, reboot if asked
In case you have Windows 10 Home edition (so you have no Hyper-V at all), you can use alternative for Optimize-VHD cmdlet:
wsl --shutdown
diskpart
# open Diskpart in new window
select vdisk file="C:\WSL-Distros\…\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exitThanks to @merkuriy for the tip.