So, I'm having a strange problem.
I have a weekly scheduled task to run this script that gets host and VM count. It had been working fine for months.
Suddenly the VM count has been incorrect.
-----
Get-Cluster NAMEOFCLUSTER | Select Name, @{N="Host Count"; E={($_ | Get-VMHost).Count}}, @{N="VM Count"; E={($_ | Get-VM).Count}} | Export-Csv C:\Folder\file.csv
-----
So I started troubleshooting. I took it back to basics and ran a "Get-Cluster NAMEOFCLUSTER" and it's working fine.
Soon as I pipe "Get-VM" to it, it doesn't work correctly. It will get a few VMs sometimes and then crash with this error:
-----------------------------
get-vm : 4/30/2018 11:24:43 AM Get-VM Exception has been thrown by the target of an invocation.
At line:1 char:33
+ Get-Cluster NAMEOFCLUSTER | get-vm
+ ~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
-----------------------------
It's strange, sometimes it will get more of the VMs than other times. Sometimes it wont get any at all and just throw that error.
If I just do a "Get-VM" without piping from "Get-Cluster" then it does get all the VMs correctly.
I tried to call VMware support about it but they said I had to have SDK Support for this issue and the standard ESXi/vCenter Support didn't cover this.
I've rebooted the vCenter but it didn't help.
Any ideas why this is suddenly failing?
Thanks!
I uninstalled PowerCLI 6.3 and then I installed version 10 and now it works. Not sure why but oh well. Thanks for the suggestions LucD.
Which PowerCLI (Get-PowerCLIVersion) and PowerShell ($PSVersionTable) version are you running?
What OS are you running this from?
Did you stop/start your PowerCLI session in between these tests?
Did it make any difference?
Do you have this on different stations (where you installed PowerCLI)?
Are you connected to one or more vSphere servers (vCenter and/or ESXi)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try uninstalling/installing PowerCLI?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I am running PwerCLI 6.3 Release 1 build 3737840.
It's powershell version 4.0.
I'm on a Windows 2012 R2 Standard server.
I can close PowerCLI and reopen, it makes no difference.
I don't have PowerCLI on another computer right now but i can install on another to try.
It happens whether I use the 32 or 64 bit PowerCLI.
I'm connected only to 1 vCenter.
I haven't uninstalled yet, but I will try to uninstall and install a newer version.
I uninstalled PowerCLI 6.3 and then I installed version 10 and now it works. Not sure why but oh well. Thanks for the suggestions LucD.