If you have both Powercli and Hyper-v Powershell module installed, then an error may pop up when calling some identical commands such as Get-VM

So I need to get the list of VMs from my vCenter server, after I ran Get-VM, I got the following error

get-vm : The Hyper-V Management Tools could not access an expected WMI class on computer 'PC-Name'. This may indicate
that the Hyper-V Platform is not installed on the computer or that the version of the Hyper-V Platform is incompatible
with these management tools.
At line:1 char:1
+ get-vm
+ ~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-VM], VirtualizationException
    + FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.GetVM

Even though I loaded the PowerCLI module, but it sometimes works and the other not, so to have an easy fix for this just use the following

ModuleName\CommandName

VMware.VimAutomation.Core\Get-VM

This method will ensure that the call is reaching the Get-VM which is located in the VMware module, not the hyper-v module

I got this when I was using my script to Automate moving VMs and placing the server in Maintenance Mode

Hope this help.

3/5 - (2 votes)