I'm trying to use Resize-VHD cmdlet, but this results in the following error:

PS> Resize-VHD -Path "C:\Container.vhd" -SizeBytes 20GB
        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 : CommandNotFoundException

How do I fix that?

  • 1
    LoL! Another Masochistic Windowism! Not making basic Window functionality available, even though all other commands (via CMD) and GUI is available, but not the most basic powershell stuff like mounting your VHD!
    – not2qubit
    Jan 17, 2020 at 18:57
  • to mount a vhd you can use diskpart. Feb 19, 2021 at 2:58

2 Answers 2


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)

  1. Go to Control Panel | Programs and features | Turn windows features on or off
  2. Tick Hyper-V | Hyper-V Management tools | Hyper-V Module for Windows PowerShell
  3. When installed, reboot if asked
  • 8
    Well, I had to install the Hyper-V Platform | Hyper-V Services part, too. (Which requires a reboot.) Resize-VHD finally started working only after that. Note: I was worried (as I've seen pranks like that from MS, and others...), but Hyper-V Services fortunately does not require a Hyper-V capable hardware.
    – Sz.
    Jul 17, 2018 at 22:54
  • Can we at least enable this from Powershell?
    – not2qubit
    Jan 17, 2020 at 18:58
  • This doesn't work for Windows 8.1 as the Hyper-V features are not available. Is there a ways to install this by side loading?
    – not2qubit
    Jan 17, 2020 at 19:22
  • This is incorrect, I do have Hyper-V on my Windows 8.1
    – Codeguard
    Jan 18, 2020 at 19:50
  • 3
    In case anyone can't find Hyper-V like I couldn't, you can only have Hyper-V if you're on Windows 10 Enterprise, Pro, or Education (source).
    – joshua
    Apr 19, 2021 at 4:26

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
# open Diskpart in new window
select vdisk file="C:\WSL-Distros\…\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk

Thanks to @merkuriy for the tip.

  • I do have Windows Enterprise, but for some reason, Windows refused to install the component of Hyper-V for PowerShell, so I used this method, and it totally worked. Nov 8, 2022 at 10:15
  • wsl --shutdown, not commonly mentioned but fixes many issues
    – J. Doe
    Sep 26 at 17:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .