VMware Cloud Community
scotty_p
Enthusiast
Enthusiast
Jump to solution

Get VMhost of a VM

Hello,

I'm trying to get the host that a list of VMs are on, but I'd also like the VM name printed out so I know what VM I'm looking at.

For example, if I run 'get-vm | get-vmhost', I get the output below. I can see the name of the host, but I don't know what the actual VM is. Is there a way to include the VM name in this output as well?

Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz   MemoryUsageGB   MemoryTotalGB Ver
                                                                                                               sio
                                                                                                                 n
----                 --------------- ---------- ------ ----------- -----------   -------------   ------------- ---
204.154.130.151      Connected       PoweredOn       8         126       18080          19.774          23.987 0.0
labesxi1.hq.tella... Connected       PoweredOn      12        2057       36696          45.648          95.987 1.0
usnvwvf5esx2.hq.t... Connected       PoweredOn      16        1051       29776          42.050         127.987 0.0
usnvwvf5esx3.hq.t... Connected       PoweredOn      24        1786       47856          95.862         255.987 0.0

Thanks,

Scott

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do

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

Are there any other properties you want to list ?


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You can do

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

Are there any other properties you want to list ?


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

Reply
0 Kudos
scotty_p
Enthusiast
Enthusiast
Jump to solution

Wow! That was awesome!!!

Can you tell me what that syntax is? N=VM, E={ }. Just trying to understand how that command works.

Thanks a lot!!!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, the line has 2 cmdlets, where the objects returned by Get-VM (VirtualMachine objects) are passed through the pipeline to the Select-Object cmdlet.

On the Select-Object cmdlet I use a calculated property (the expression between @{...})

Such a calculated property consists of 2 parts, first the name (N) we want to give to the property, second the expression (E) where we calculate the value of the property.

In the VirtualMachine object the Host property holds the VMHost object, and in there we find the Name of the host.

Did that make it any clearer, or are you more confused now ?


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

Reply
0 Kudos
scotty_p
Enthusiast
Enthusiast
Jump to solution

I think that makes sense Smiley Happy

At least more than it did before.

Thanks a lot for your help Luc.

Reply
0 Kudos