July 4, 2025

USEFUL-IT

A blog for USEFUL-IT information

Running PowerShell Hyper-V and VMWare Modules

If you have the cmdlets of hyper-v and VMWare PowerCli both installed on your system. They both have cmdlets that have the same name, it is always difficult which cmdlet your script uses.
This function will help you in this matter.

Add this function to your script or default.ps1

Function Add-VMCs() {
[cmdletbinding()]
#Requires -Modules Hyper-V, VMWare.VimAutomation.Core
Param(
    [Parameter(Mandatory=$False,
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true,
        ValueFromRemainingArguments=$false,
        Position=0)]
    [ValidateSet("v", "h")]
    $Default
)
If ($Default -eq 'h' -or $Default -eq 'v') {
         Remove-Module -Name Hyper-V -ErrorAction SilentlyContinue
         Remove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue
         If ($Default -eq 'h') {
             Import-module -Name VMware.VimAutomation.Core
             Import-Module -Name Hyper-V
             Write-Host "Hyper-V module has been set as default." -ForegroundColor Green
         } ElseIf ($Default -eq 'v') {
             Import-Module -Name Hyper-V
             Import-Module -Name VMware.VimAutomation.Core
             Write-Host "VMWare module has been set as default." -ForegroundColor Green
         }
     } Else {
         Write-Output -Verbose "INFO: No changes made`r`nUse H to set Hyper-V as the default (Add-VMCs H) or use V to set VMware as the default (Add-VMCs V)."
     }
 }

Source : Cmdlets of the Same Name (VMware & Hyper-V) – tommymaynard.com

Activate VMWare Module

PS C:\> Add-VMCs V
VMWare module has been set as default.
PS C:\> Get-command Get-VM

CommandType     Name    Version    Source
-----------     ----    -------    ------
Cmdlet          Get-VM  13.2.0.22… VMware.VimAutomation.Core

Activate Hyper-V Module

Add-VMCs H # for Hyper-V Module

PS C:\Users\wesse> Add-VMCs H
Hyper-V module has been set as default.
PS C:\Users\wesse> Get-command Get-VM

CommandType     Name    Version    Source
-----------     ----    -------    ------
Cmdlet          Get-VM  2.0.0.0    Hyper-V

About The Author