- Disk Cleanup -> Cleanup system files
- Turn off VM
- Attach VHD as a drive (for example V:)
- Delete pagefile.sys and swapfile.sys if you don't want them to be in the parent VHD. They will be created again in the child VHD when Windows starts.
- defrag V: /h /u /v /x
- sdelete -s -z V:
- Detach VHD
- Optimize-VHD $vhdx_file -Mode full