VMware Cloud Community
simonadams
Contributor
Contributor
Jump to solution

Inefficient basic query

Hi All

I have a basic requirement of listing all VM's on each Virtualcentre with their host name and cluster.

And this is a way of doing it;

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, @{N="ESX Host";E={Get-VMHost -VM $_}}

But this seems very slow and I guess I'm going around the loops each time to get basic information that I assume I could get in one go as a property of the machine ?

If any of you have a more efficient way of doing it I'd appreciate it.  To be honest I only really need the host name as I can map that to a cluster name.  But even;

Get-VM | Select Name, @{N="ESX Host";E={Get-VMHost -VM $_}}

is slow (and presumably inefficient)...

Appologies for the stupid question in advance!

Many thanks

Simon

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This should be faster

Get-VM | Select Name,@{N="Host";E={$_.Host.Name}}

PS: there are no stupid questions 🙂


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

This should be faster

Get-VM | Select Name,@{N="Host";E={$_.Host.Name}}

PS: there are no stupid questions 🙂


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

0 Kudos
simonadams
Contributor
Contributor
Jump to solution

Yes thats much better - I'll get my head around this stuff one day!

Many thanks - brilliantly helpful as always

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks, I nice trick, beside the Get-Member cmdlet, to explore objects returned by PowerCLI is this

Get-VM | Format-Custom -Depth 2

With the Depth parameter you define how deep you want to go in the nested objects.


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

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To get the clustername as well you can do:

Get-VM | Select Name,@{N="Host";E={$_.Host.Name}},@{N="Cluster";E={$_.Host.Parent}}


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos