Cmdlet Contention between PowerShell SnapIns

569 Views Asked by At

I ran into an issue while using both the Vmware PowerCLI and System Center Virtual Machine Manager snap-ins for PowerShell. They both contain similarly named cmdlets, like 'Get-VM' and '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. 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?

2

There are 2 best solutions below

0
On

The best approach when using snapins is to fully qualify the cmdlet name with the snapin name. For instance, if the snapin name for PowerCLI is PowerCLI then use:

PowerCLI\Get-VM

For the SCVMM snapin use it's name as a prefix. To see the snapin names, execute:

Get-PSSnapin -Registered
0
On

And for anyone searching for the actual namespace/prefix for VMware's vSphere PowerCLI snapin cmdlets, it's:

VMWare.VimAutomation.Core

Hence the real prefix for the example above is:

VMware.VimAutomation.Core\Get-VM