How to correctly invoke a PowerShell Function that has the same name in two Libraries

How to correctly invoke a PowerShell Function that has the same name in two Libraries

I am currently authoring a PowerShell reporting script that exclusively uses functions from the Windows Server 2012 Hyper-V API.  When I imported the module for System Center Virtual Machine Manager, I noticed that a function that I previously used was giving me an error:

Get-SCVMHost : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ComputerName'. Specified method is not supported.

Get-SCVMHost : Cannot convert ‘System.Object[]’ to the type ‘System.String’ required by parameter ‘ComputerName’. Specified method is not supported.

I then realized that the Get-VMHost commandlet was now being invoked from the SCVMM library, which does not support getting hosts from an array of names like the Hyper-V API does.  So how does how go about letting PowerShell know that we want to use the Get-VMHost commandlet from Hyper-V?

I had no idea, and searching the web yielded nothing.  I then followed my Visual Studio instinct and thought intelisense would shed some light…and it did.

When I right-clicked and selected Start Intellisense on the function, I could see which library it was using:

The Get-Host from SCVMM is the one being used

The Get-Host from SCVMM is the one being used

I scrolled down a bit more and found the one I wanted:

Hyper-V API Function

Hyper-V API Function

Once I selected the correct function, PowerShell ISE took care of the rest and wrote down the syntax (which I had no idea about) to avoid ambiguity when calling functions:

pac0915 2013-02-18 10-03-59

Leave a Reply