VMware Cloud Community
amarcy
Contributor
Contributor

Get-View Guest.Hostname property returning null

Can anyone tell me why this one liner only returns the VM name and not the Guest Host name?

Get-View -ViewType VirtualMachine -Property Name -Filter @{"Guest.HostName" = ".*$prompt.*"} | Select @{N='VM Name';E={$_.Name}}, @{N='Guest Host Name';E={$_.Guest.HostName}} | ft -wrap -auto

Thanks!

Reply
0 Kudos
3 Replies
DZ1
Hot Shot
Hot Shot

$_.Guest.Hostname is not the ESXi host, it's the name of the VM.  You could see the host by selecting Get-VMhost -id $_.Runtime.Host, since you're using Get-View.

Reply
0 Kudos
amarcy
Contributor
Contributor

Sorry for the late reply.  I understand that $_.Guest.Hostname returns the VM machine name.  My problem is that the query is returning nothing in the second part of my select statement.  The first column should return the VM name, and the second column should return the VM machine name.  I don't know why it's not returning the latter. 

And just to clarify, I'm not interested in the ESXi host name.  Thanks.

Reply
0 Kudos
amarcy
Contributor
Contributor

Figured it out, I was missing the Guest.HostName property when defining parameters of get-view:

Get-View -ViewType VirtualMachine -Property Name, Guest.HostName

Reply
0 Kudos