VMware Cloud Community
Cegalian
Contributor
Contributor
Jump to solution

Can't restart, start, stop or suspend VM's with PowerCLI

I can't seem to interact with any VM's when connected to my vCenter. I've also tried connecting directly to both my ESXI hosts but I get the same error.

What I wanted to do was create a script that restarts all VM's contained in a specific folder.

Something like this: Get-Folder "PROD" | Get-VM | Restart-VMGuest

But now I see that I can do much other than Get-VM alone, I can also do Get-VM | Get-Snapshots without any issues.

I've reinstalled PowerCLI and tried on another computer as well. But this error doesn't tell me much.

PowerCLI.png

Best Regards - Alexander
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That is a rather old version of PowerCLI you seem to be using  (6.5 R1).

Can you do a complete uninstall, remove all PowerCLI related folders, and then try a fresh install (with Install-Module)?
Find more elaborate instructions  in Welcome PowerCLI to the PowerShell Gallery – Install Process Updates

The previous mention we had of this kind of error was also caused by an installation gone wrong.

See Re: Get-VM Exception has been thrown by the target of an invocation.


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

That is a rather old version of PowerCLI you seem to be using  (6.5 R1).

Can you do a complete uninstall, remove all PowerCLI related folders, and then try a fresh install (with Install-Module)?
Find more elaborate instructions  in Welcome PowerCLI to the PowerShell Gallery – Install Process Updates

The previous mention we had of this kind of error was also caused by an installation gone wrong.

See Re: Get-VM Exception has been thrown by the target of an invocation.


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

0 Kudos
Cegalian
Contributor
Contributor
Jump to solution

Thank you LucD! I'll try importing / installing using powershell. Allready did a re-install couple times and tried PowerCLI on another machine but got the same error. I'll let you know if it works Smiley Happy

Best Regards - Alexander
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I would strongly advise not to go for a 6.5 R1 reinstall anymore.

But do a recent version, currently 11.0.0, from the PowerShell Gallery with Install-Module.

You better check your PowerShell version as well (with $PSVersionTable).
Ideally you should aim at PS v5.1.

It is very important that you clan up all old versions.
Do a uninstall from the Control Panel, but then also remove all PowerCLI directories.
You can check which directories by displaying $env:PSModulePath.Split(';')
All folders starting with VMware in any of the folders listed shall be removed.

That is all mentioned in the post I pointed you to earlier.


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

Cegalian
Contributor
Contributor
Jump to solution

Big thanks LucD ! Worked great. Using PowerCLI 11.0.0 installed inside powershell. All commands seems to work OK now!

Best Regards - Alexander
mviel
Enthusiast
Enthusiast
Jump to solution

Maybe you give "Powershell Core" ( the Powershell Version which works "CrossPlattform" ) a try https://github.com/PowerShell/PowerShell

The Nice thing , which works for me that that I get a Plattform which works on Linux or Windows alike  . There is also no Problem with already installed Modules on the Computer as the Powershell Core is a seperate Instance.

PowerCLI Core

GitHub - PowerShell/PowerShell: PowerShell for every system!

Good Luck

0 Kudos