Powershell Resize-VHD 未被识别为 cmdlet 的名称

Cod*_*ard 13 powershell vhd

我正在尝试使用Resize-VHDcmdlet,但这会导致以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

小智 37

如果您使用的是 Windows 10 家庭版(因此根本没有 Hyper-V),您可以使用 Optimize-VHD cmdlet 的替代方案:

\n
wsl --shutdown\ndiskpart\n# open Diskpart in new window\nselect vdisk file="C:\\WSL-Distros\\\xe2\x80\xa6\\ext4.vhdx"\nattach vdisk readonly\ncompact vdisk\ndetach vdisk\nexit\n
Run Code Online (Sandbox Code Playgroud)\n

感谢@merkuriy 的提示

\n


Cod*_*ard 17

原来我需要在 Windows 上安装 Hyper-V 功能(即使我不需要 Hyper-V 本身,我使用 VHD 作为便携式文件容器)

  1. Control Panel | Programs and features | Turn windows features on or off
  2. 打钩 Hyper-V | Hyper-V Management tools | Hyper-V Module for Windows PowerShell
  3. 安装后,如果询问,请重新启动

  • 好吧,我不得不安装`Hyper-V Platform | Hyper-V 服务部分也是如此。(这需要重新启动。)`Resize-VHD` 最终才开始工作。注意:我很担心(因为我看到过来自 MS 和其他人的恶作剧......),但幸运的是“Hyper-V 服务”不需要支持 Hyper-V 的硬件。 (4认同)
  • 如果有人像我一样找不到 Hyper-V,那么只有使用 Windows 10 企业版、专业版或教育版才能拥有 Hyper-V([来源](https://docs.microsoft.com /en-us/虚拟化/hyper-v-on-windows/quick-start/enable-hyper-v))。 (3认同)