VMware Cloud Community
iefke
Enthusiast
Enthusiast

get-vmhost | get-vm

The command "Get-VMhost -name ESXhost | Get-VM" return more VMs than that there on the VMware ESX host currently. Anybody seen this before?

Blog: http://www.ivobeerens.nl
0 Kudos
12 Replies
gboskin
Enthusiast
Enthusiast

its probably returning all the VM on the host ( ESXHost) both powered on and powered off...

0 Kudos
halr9000
Commander
Commander

Maybe it's the dreaded "VM creep" Smiley Happy




[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
esarakaitis
Enthusiast
Enthusiast

is it showing your templates as well?

0 Kudos
iefke
Enthusiast
Enthusiast

No its one VMware ESX server of a cluster of 8 servers. I did a VMotion of all VMs except one on the VMware ESX server . Only one VM active and no powered off VMs or templates.

Blog: http://www.ivobeerens.nl
0 Kudos
esarakaitis
Enthusiast
Enthusiast

what script are you using?

are you specifying the esx-hostname?? if not, it might pull all of the vm's of the cluster/dc

0 Kudos
iefke
Enthusiast
Enthusiast

Yes i'am specifying the ESX hostname

Get-VMhost -name ESXhostname | Get-VM"

Blog: http://www.ivobeerens.nl
0 Kudos
esarakaitis
Enthusiast
Enthusiast

looks like from my testing its getting the entire cluster...

try connecting directly to the host instead of vc and see if you see the same results

0 Kudos
iefke
Enthusiast
Enthusiast

connecting directly to the host works, but i want to make a script that all VMs on the specified ESX hosts get vmotioned with the move-vm command.

Blog: http://www.ivobeerens.nl
0 Kudos
halr9000
Commander
Commander

See if this works:

( Get-VMHost foo | Get-View ).VM | foreach-object { $_ | Get-VIObjectByVIView }






[PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
esarakaitis
Enthusiast
Enthusiast

figured it out, seems like a bug...

try: Get-VM | Where-Object {$_.Host.Name -eq "esxhost"}

0 Kudos
esarakaitis
Enthusiast
Enthusiast

$hostinfo = get-vmhost "vmhostname"

$vmviews = (Get-View $hostinfo.ID).VM

$vmviews | % {

$_ | Get-VIOBjectByVIView

}

0 Kudos
yboychev
Hot Shot
Hot Shot

Hi,

Could you please give some more details about the environment against which you are reproducing this issue. I've tried to reproduce it against a vc that has a couple of hosts inside a single cluster each containing several vms. When I execute Get-Vmhost -Name MyESX | Get-Vm everything seems to be OK and the result contains only the vms from MyESX.

Which version of the toolkit (Get-VIToolkitVersion) are you using?

10x in advance for the info!

\Yavor

0 Kudos