Skip to main content
 首页 » 编程设计

powershell之添加前如何验证管理单元

2024年12月31日13Renyi-Fan

我在 Powershell 中遇到以下编译问题。

Add-PSSnapin : Cannot add Windows PowerShell snap-in VMware.VimAutomation.Core because it is already added. Verify the name of the snap-in and try again.



该错误明确提到我需要验证管理单元的名称。当我第一次执行时它已成功添加。

如何验证管理单元是否存在,如果不存在则添加?

请您参考如下方法:

如果尚未加载,您可以加载它:

if(-not (Get-PSSnapin VMware.VimAutomation.Core)) 
{ 
   Add-PSSnapin VMware.VimAutomation.Core 
} 

您也可以无论如何加载它并忽略错误:
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue