VMware Cloud Community
madpro
Enthusiast
Enthusiast
Jump to solution

Issue running Powercli script in Powershell ISE

Hi there

So i use ISE for both Powershell and PowerCLi scripting, but I have recently noticed an issue with a script I use.

The script I use deploys Linked Clones to our ESXi environment, and until recently has been running fine in the ISE.

I now get an error saying the Hyper-V role is not installed on the destination host.

I assume I am getting this because the Script i run uses the Get-VM command, and this command is also a Hyper-V command

I am not sure how to resolve this and differentiate the 2 commands

Thanks for your help

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, since PowerCLI 6.5R1 there are no more PSSnapin, only modules.

The Hyper-V module is installed on your system when you for example install the Remote Administration Tools on your desktop.

Once the Hyper-V module is installed, the cmdlets in that module are automatically "known" to the PowerShell engine, through something that is called auto-loading and the folders defined in the $env:PSModulePath variable.

The Hyper-V module contains a Get-VM cmdlet.

When you now load the PowerCLI modules, you get the PowerCLI version of the Get-VM cmdlets as well.

You can check by running

Get-Command -Name Get-VM

The easiest solution is of course not to load cmdlets with the same name from multiple modules.

If you don't use Hyper-V, you could remove/rename the Hyper-V module folder.

Otherwise you can the Prefix parameter on the Import-Module cmdlet.

Import-Module -Name Hyper-V -Prefix 'HV'

Get-HVVM

This way the cmdlets in the Hyper-V module get the Prefix you specified on the Noun part of the cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
9 Replies
Sreejesh_D
Virtuoso
Virtuoso
Jump to solution

0 Kudos
madpro
Enthusiast
Enthusiast
Jump to solution

Thanks yezdi

I'll have a read of the article

I'm wondering why its just started happening..I dont think anything has changed recently on my system.....

0 Kudos
Sreejesh_D
Virtuoso
Virtuoso
Jump to solution

by any chance did you enable the hyperv role on your machine?

0 Kudos
vijayrana968
Virtuoso
Virtuoso
Jump to solution

Is Powershell ISE loading PowerCLI module correctly ? This should happen when Powershell doesn't recognize PowerCLI commands. Try executing below command before script.

Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

0 Kudos
madpro
Enthusiast
Enthusiast
Jump to solution

No, I havent done that yet

I am running a server 2012 VM inside ESXi 5.5

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version are you running?

Do a Get-PowerCLIVersion


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
madpro
Enthusiast
Enthusiast
Jump to solution

I am running -  VMware PowerCLI 6.5 Release 1 build 4624819

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, since PowerCLI 6.5R1 there are no more PSSnapin, only modules.

The Hyper-V module is installed on your system when you for example install the Remote Administration Tools on your desktop.

Once the Hyper-V module is installed, the cmdlets in that module are automatically "known" to the PowerShell engine, through something that is called auto-loading and the folders defined in the $env:PSModulePath variable.

The Hyper-V module contains a Get-VM cmdlet.

When you now load the PowerCLI modules, you get the PowerCLI version of the Get-VM cmdlets as well.

You can check by running

Get-Command -Name Get-VM

The easiest solution is of course not to load cmdlets with the same name from multiple modules.

If you don't use Hyper-V, you could remove/rename the Hyper-V module folder.

Otherwise you can the Prefix parameter on the Import-Module cmdlet.

Import-Module -Name Hyper-V -Prefix 'HV'

Get-HVVM

This way the cmdlets in the Hyper-V module get the Prefix you specified on the Noun part of the cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
madpro
Enthusiast
Enthusiast
Jump to solution

Thanks LucD, I renamed the folder and the script is working fine

0 Kudos