按照官方文档,你应该这样卸载:
- Open PowerShell.
- To uninstall all VMware PowerCLI modules except VMware.PowerCLI, run the command:
(Get-Module VMware.PowerCLI -ListAvailable).RequiredModules | Uninstall-Module -Force
- To uninstall the VMware PowerCLI main module, run the command.
Get-Module VMware.PowerCLI -ListAvailable | Uninstall-Module -Force
但当我实际运行时,收获了这个异常:
某 Module 当前正在使用中或者你没有必需的权限
怀疑是 powershell 启动时,就加载了 PowerCLI 的某些 Module,导致无法卸载,于是通过以下步骤卸载:
- 关闭所有 powershell
最好把 Intelij IDEA, VSCode 等软件都关掉,因为其中的终端也可能使用 powershell。
- 以管理员权限启动 cmd,并执行:
powershell -NoProfile -Command "(Get-Module VMware.PowerCLI -ListAvailable).RequiredModules | Uninstall-Module -Force"
- 正常卸载 PowerCLI 主模块:
Get-Module VMware.PowerCLI -ListAvailable | Uninstall-Module -Force
为什么我要卸载 PowerCLI,因为 PowerCLI 的命令和 Hyper-V 冲突了,虽然可以通过 module prefix
的形式避免,但我不乐意😋
啥是 module prefix? 以下举例:
VMware.VimAutomation.Core\Get-VM