VMware Cloud Community
esxi1979
Expert
Expert
Jump to solution

extensiondata does not show up some values "directly"

Some of the values does not come up straight .. eg

(get-vm -name name1).extensiondata.runtime.host

Type

----

HostSystem

In above case how do we get the value of the VM's host ?

thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is, like this

Get-View -ViewType VirtualMachine -Property Name,"runtime.host" |

Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}}

And if you want a specific VM, you can do

$vmName = "MyVM"

Get-View -ViewType VirtualMachine -Property Name,"runtime.host" -Filter @{"Name"=$vmName} |

Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}}


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

View solution in original post

0 Kudos
13 Replies
deang1609
Enthusiast
Enthusiast
Jump to solution

My assumption is that you are trying to retrieve the host name to which the VM resides, you could achieve this by invoking the Get-VM cmdlet as below:

(Get-VM name1).VMHost.Name

From your example, the value that will be retrieved will be the Host Id value and not the name, but you could return the value as below:

((Get-VM -Name name1).Extensiondata.Runtime.Host).Value
Dean Grant Blog: deangrant.wordpress.com | Twitter: @dean1609 | GitHub: https://github.com/dean1609
LucD
Leadership
Leadership
Jump to solution

What Dean said is correct, but to clarify a bit further.

The ExtensionData property of PowerCLI objects, aka .Net objects, maps to the read-only copy of the corresponding vSphere object.

In this case for a .Net VirtualMachine object, the ExtensionData property will map to a vSphere VirtualMachine object.

Although the objects are named the same, they are 2 different objects.

To see what properties are in the vSphere object, you consult the API Reference.

If you follow the path to Host property you are using, you will see that the property holds a MoRef (which is a pointer to another vSphere object).

host-moref.png

To get the vSphere object the MoRef is pointing, you can use the Get-View cmdlet.

Get-View -Id (Get-VM -Name MyVM).ExtensionData.Runtime.Host


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

esxi1979
Expert
Expert
Jump to solution

((Get-VM -Name name1).Extensiondata.Runtime.Host).Value


did not give the expected output tho Smiley Sad

0 Kudos
Zsoldier
Expert
Expert
Jump to solution

What value are you expecting?

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

Yes, I understand that, but given the first answer would have ultimately been the quickest way, I was responding to the very last comment.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
esxi1979
Expert
Expert
Jump to solution

Thanks,

Get-View -Id (Get-VM -Name MyVM).ExtensionData.Runtime.Host

does revile the name of the vm's host, but there is no easy way to get this with " get-view -ViewType VirtualMachine" Smiley Sad

Then cluster too.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is, like this

Get-View -ViewType VirtualMachine -Property Name,"runtime.host" |

Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}}

And if you want a specific VM, you can do

$vmName = "MyVM"

Get-View -ViewType VirtualMachine -Property Name,"runtime.host" -Filter @{"Name"=$vmName} |

Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}}


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

0 Kudos
esxi1979
Expert
Expert
Jump to solution

Thanks that did work... But the purpose of using get-view does not meet as its taking a lot of time with this added change .. Smiley Sad

0 Kudos
esxi1979
Expert
Expert
Jump to solution

i think its even slower than , get-vm |selec name, vmhost ..

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Very strange, how many VMs do you have in that environment ?


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

0 Kudos
esxi1979
Expert
Expert
Jump to solution

Here is the o/p

PowerCLI C:\> Measure-Command {get-vm |select name,vmhost}

Days              : 0

Hours             : 0

Minutes           : 0

Seconds           : 32

Milliseconds      : 791

Ticks             : 327911132

TotalDays         : 0.000379526773148148

TotalHours        : 0.00910864255555555

TotalMinutes      : 0.546518553333333

TotalSeconds      : 32.7911132

TotalMilliseconds : 32791.1132

PowerCLI C:\> Measure-Command {Get-View -ViewType VirtualMachine -Property Name,"runtime.host" |Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}} }

The last cmd will give o/p may be after 30 min or 1 hr is my estimate .. but it gives info correct ..

btw i have 1500 vms

0 Kudos
esxi1979
Expert
Expert
Jump to solution

also ran it for single vm

PowerCLI C:\> Measure-Command {get-vm xxxxxxxx |select name,vmhost}

Days              : 0

Hours             : 0

Minutes           : 0

Seconds           : 8

Milliseconds      : 191

Ticks             : 81913350

TotalDays         : 9.48071180555556E-05

TotalHours        : 0.00227537083333333

TotalMinutes      : 0.13652225

TotalSeconds      : 8.191335

TotalMilliseconds : 8191.335

PowerCLI C:\> $vmName = "xxxxxxxx"

PowerCLI C:\>

PowerCLI C:\> Measure-Command {Get-View -ViewType VirtualMachine -Property Name,"runtime.host" -Filter @{"Name"=$vmName} |Select @{N="VM";E={$_.Name}},@{N="ESXi";E={Get-view -Id $_.runtime.host | select -ExpandProperty Name}} }

Days              : 0

Hours             : 0

Minutes           : 0

Seconds           : 11

Milliseconds      : 540

Ticks             : 115409488

TotalDays         : 0.000133575796296296

TotalHours        : 0.00320581911111111

TotalMinutes      : 0.192349146666667

TotalSeconds      : 11.5409488

TotalMilliseconds : 11540.9488

PowerCLI C:\>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Get-View variation is doing a lot more of course, compared to the Get-VM with the Select-Object.

In this case you should go for the simple Get-VM.

But the original question was why the runtime.host property didn't give the ESXi hostname.

The short answer, because it returns a MoRef.


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

0 Kudos