Powershell Resize-VHD is not recognized as the name of a cmdlet

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

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
exit

Thanks to @merkuriy for the tip.