简体   繁体   English

PowerShell管理单元之间的Cmdlet争用

[英]Cmdlet Contention between PowerShell SnapIns

I ran into an issue while using both the Vmware PowerCLI and System Center Virtual Machine Manager snap-ins for PowerShell. 在将Vmware PowerCLI和System Center Virtual Machine Manager管理单元用于PowerShell时遇到问题。 They both contain similarly named cmdlets, like 'Get-VM' and 'Get-VMHost'. 它们都包含类似命名的cmdlet,例如“ Get-VM”和“ Get-VMHost”。 It appears that the last snap-in to load wins, so I added logic in my script to load & un-load the snap-in when I needed to get either VMware data or Hyper-V data. 看来最后一个要加载的管理单元胜出了,所以我在脚本中添加了逻辑,以在需要获取VMware数据或Hyper-V数据时加载和卸载该管理单元。 I'd like to know if there is any way to prevent this contention, or otherwise create some unique handle to one cmdlet, while still allowing the other to load & operate as intended? 我想知道是否有任何方法可以防止这种争用,或者以其他方式为一个cmdlet创建一些唯一的句柄,同时仍然允许其他cmdlet按预期方式加载和运行?

The best approach when using snapins is to fully qualify the cmdlet name with the snapin name. 使用管理单元时最好的方法是用管理单元名称完全限定cmdlet名称。 For instance, if the snapin name for PowerCLI is PowerCLI then use: 例如,如果PowerCLI的管理单元名称为PowerCLI,则使用:

PowerCLI\Get-VM

For the SCVMM snapin use it's name as a prefix. 对于SCVMM管理单元,请使用其名称作为前缀。 To see the snapin names, execute: 要查看管理单元名称,请执行:

Get-PSSnapin -Registered

And for anyone searching for the actual namespace/prefix for VMware's vSphere PowerCLI snapin cmdlets, it's: 对于搜索VMware vSphere PowerCLI snapin cmdlet的实际名称空间/前缀的任何人,它是:

VMWare.VimAutomation.Core

Hence the real prefix for the example above is: 因此,上面示例的真正前缀是:

VMware.VimAutomation.Core\Get-VM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM