Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerCLI Get-VMhost The operation on computer failed The WinRM client cannot process the request

I frequently get error winrm client cannot process the request while running few VMware PowerCLI commands for example: Get-VM, Get-VMhost etc. The complete error is highlighted as below in the Red, This generally happens due to duplicate cmdlet name in the another module.

Microsoft Powershell Module PowerCLI vmware.Powercli vmware vsphere esxi connect-viserver import-module get-vmhost winrm hyper-v module vcenter server vcsa vsphere client visual studio code.png

Import-Module VMware.PowerCLI
          Welcome to VMware PowerCLI!

Log in to a vCenter Server or ESX host:              Connect-VIServer
To find out what commands are available, type:       Get-VICommand
To show searchable help for all PowerCLI commands:   Get-PowerCLIHelp
Once you've connected, display all virtual machines: Get-VM
If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

       Copyright (C) VMware, Inc. All rights reserved.

Specify Credential
Please specify server credential
User: [email protected]
Password for user [email protected]: **********

Get-VMhost : The operation on computer '' failed: The WinRM client cannot process the request. If the authentication 
scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the
destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers   
in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help   
At line:1 char:1
+ Get-VMhost | Get-VMHostHba | Where-Object {$_. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-VMHost], VirtualizationException
    + FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.GetVMHost

The exact root of the issue is there is a another Microsoft Module exists in your OS for Hyper-V. Few of the cmdlet name are identical between Hyper-V and VMware.PowerCLI module, Because of the similarities you will need to unload Hyper-v Module. This also happens due to Hyper-V module gets preference and if module is not loaded and cmdlet is not found, it is searched in the Microsoft modules first generally location in C:\Windows\System32\WindowsPowerShell\v1. 0\Modules\. To resolve this you can remove module, It just unloads from PowerShell memory and does not uninstalls or delete it permanently.

Get-Command -Module Hyper-V -Name Get-VMHost 
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-VMHost                                   Hyper-V

Remove-Module Hyper-V

Next reload the VMware.PowerCLI module again by importing it, and try running common cmdlets you will get the desired output as you are looking for.

Get-Command -Module VMware.VimAutomation.Core -Name Get-VMHost
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-VMHost                                         12.0.0.... VMware.VimAutomation.Core 

Import-Module VMware.PowerCLI

Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz   MemoryUsageGB   MemoryTotalGB Version
----                 --------------- ---------- ------ ----------- -----------   -------------   ------------- -------
ironman.vcloud-la... Connected       PoweredOn       2          90        6428           1.203           3.999   7.0.0

vmware.powercli module powershell remove-module hyper-v Import-Module get-command -module vmware.vimautomation.cor -name get-vmhost get-vmhosthba where-object hba model scsi controller.png

To permanently fix this issue in your scripts always add a line to Remove-Module ModuleName in the beginning of your script.

Useful Articles
Powercli GUI: Determine the EVC Mode that vmware cluster should be configured
vMotion from all VMs on selected Esxi Host to other Esxi host via PowerCLI GUI
Powercli Get vCenter licenses information
Powercli Get vCenter assigned licenses report
PowerCLI one-liner Reporting, Chaning, Assigning and Removing licenses on ESXi

Go Back


Blog Search

Page Views


Follow me on Blogarama