![Powershell Resize-VHD 未被识别为 cmdlet 的名称](https://linux22.com/image/1556697/Powershell%20Resize-VHD%20%E6%9C%AA%E8%A2%AB%E8%AF%86%E5%88%AB%E4%B8%BA%20cmdlet%20%E7%9A%84%E5%90%8D%E7%A7%B0.png)
我正在尝试使用Resize-VHD
cmdlet,但导致以下错误:
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 : CommandNotFoundException
我该如何修复它?
答案1
事实证明我需要在 Windows 上安装 Hyper-V 功能(尽管我不需要 Hyper-V 本身,但我使用 VHD 作为便携式文件容器)
- 去
Control Panel | Programs and features | Turn windows features on or off
- 打钩
Hyper-V | Hyper-V Management tools | Hyper-V Module for Windows PowerShell
- 安装后,如果系统提示,请重新启动
答案2
如果您使用的是 Windows 10 家庭版(因此您根本没有 Hyper-V),则可以使用 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
感谢@merkuriy提示。