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

Warning
This blog post is included for archival purposes and may contain outdated information. While it provides historical insights, we strongly recommend that you double-check the details before relying on any of the information outlined here.

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

About Author

Christian Saborio

Christian is a seasoned computer engineer with a rich career spanning collaborations with industry leaders such as Artinsoft (now Mobilize.net), Microsoft, HP, and Intel. As a technical evangelist and trainer, Christian honed his expertise in Costa Rica and Seattle, delivering impactful solutions and sharing his knowledge.

Now based in Sydney, Australia, Christian channels his passion into web development, leading a talented team to tackle diverse projects with innovation and precision. His commitment to crafting exceptional digital experiences reflects his deep-rooted enthusiasm for technology and problem-solving.

Comments

    Comments are closed

    Thank you for your interest. Please fill out this form to provide us with your contact information. We'll get back to you as soon as possible.