<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Efficient way to get host's name from VM (vim.VirtualMachine) in VMware {code} Members</title>
    <link>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2918521#M65</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Not sure if I understood what you need, but let me give a try.&lt;/P&gt;&lt;P&gt;If you are using PowerShell, you can simply call VMHost VM Property and it will return the ESXi object.&lt;BR /&gt;Ex: $vm.VMHost&lt;/P&gt;&lt;P&gt;Any other programming language, I guess you can do it through a &lt;STRONG&gt;vim.VirtualMachine&lt;/STRONG&gt; object accessing vm_obj&lt;STRONG&gt;.summary.runtime.host&amp;nbsp;&lt;/STRONG&gt;or simply vm_obj&lt;STRONG&gt;.runtime.host&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Have a look on&amp;nbsp;&lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1ef6c336-7bef-477d-b9bb-caa1767d7e30/82521f49-9d9a-42b7-b19b-9e6cd9b30db1/vim.vm.RuntimeInfo.html" target="_blank"&gt;https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1ef6c336-7bef-477d-b9bb-caa1767d7e30/82521f49-9d9a-42b7-b19b-9e6cd9b30db1/vim.vm.RuntimeInfo.html&lt;/A&gt;&amp;nbsp;maybe it helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2022 11:07:24 GMT</pubDate>
    <dc:creator>FC86</dc:creator>
    <dc:date>2022-07-13T11:07:24Z</dc:date>
    <item>
      <title>Efficient way to get host's name from VM (vim.VirtualMachine)</title>
      <link>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2895011#M43</link>
      <description>&lt;P&gt;I am trying to find a highly efficient way to get a host's name from a .NET vim.virtualmachine.&lt;/P&gt;
&lt;P&gt;I have been successful in getting the MoRef for the VM, then getting all hosts with get-view and simply looping the hosts for one which contains the VM's MoRef but this is highly inefficient when doing it like this for thousands of virtual machines.&lt;/P&gt;
&lt;P&gt;I cannot find a property of&amp;nbsp;vim.virtualmachine that contains the ESXi host's name that the VM is running on, nor can I find an efficient function in the documentation.&lt;/P&gt;
&lt;P&gt;Note that I am trying to do this as efficiently as possible so I am avoiding the PowerCLI functions where possible and relying on Get-View rather than Get-Host and Get-VM (Although I can use these if there is a smart way to get the information I need efficiently)&lt;/P&gt;
&lt;P&gt;Many thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 10:54:22 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2895011#M43</guid>
      <dc:creator>virtualg_uk</dc:creator>
      <dc:date>2022-02-23T10:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to get host's name from VM (vim.VirtualMachine)</title>
      <link>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2895015#M44</link>
      <description>&lt;P&gt;So far what I have done it ran a nested for each &lt;STRONG&gt;loop&lt;/STRONG&gt; on the output of &lt;STRONG&gt;get-view -viewtype hostsystem&lt;/STRONG&gt;&amp;nbsp;with a bunch of filters and properties defined.&lt;/P&gt;
&lt;P&gt;Using the loop, I stored the host's .name value against the VMs .MoRef value in a hash table which seems to be created very quickly within the nested for each loops.&lt;/P&gt;
&lt;P&gt;Now I use reference the hash table while I loop through my VMs to get their corresponding host.&lt;/P&gt;
&lt;P&gt;I'm open to cleaner ideas if anyone has any thoughts?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 11:27:43 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2895015#M44</guid>
      <dc:creator>virtualg_uk</dc:creator>
      <dc:date>2022-02-23T11:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to get host's name from VM (vim.VirtualMachine)</title>
      <link>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2905944#M54</link>
      <description>&lt;P&gt;Would this help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$VM = get-view –viewtype VirtualMachine –filter @{“Name”=”[vmname]”}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$VM.Summary.Runtime&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Should contain the hostname.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 06:25:56 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2905944#M54</guid>
      <dc:creator>MiMenl</dc:creator>
      <dc:date>2022-04-26T06:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to get host's name from VM (vim.VirtualMachine)</title>
      <link>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2918521#M65</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Not sure if I understood what you need, but let me give a try.&lt;/P&gt;&lt;P&gt;If you are using PowerShell, you can simply call VMHost VM Property and it will return the ESXi object.&lt;BR /&gt;Ex: $vm.VMHost&lt;/P&gt;&lt;P&gt;Any other programming language, I guess you can do it through a &lt;STRONG&gt;vim.VirtualMachine&lt;/STRONG&gt; object accessing vm_obj&lt;STRONG&gt;.summary.runtime.host&amp;nbsp;&lt;/STRONG&gt;or simply vm_obj&lt;STRONG&gt;.runtime.host&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Have a look on&amp;nbsp;&lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1ef6c336-7bef-477d-b9bb-caa1767d7e30/82521f49-9d9a-42b7-b19b-9e6cd9b30db1/vim.vm.RuntimeInfo.html" target="_blank"&gt;https://vdc-repo.vmware.com/vmwb-repository/dcr-public/1ef6c336-7bef-477d-b9bb-caa1767d7e30/82521f49-9d9a-42b7-b19b-9e6cd9b30db1/vim.vm.RuntimeInfo.html&lt;/A&gt;&amp;nbsp;maybe it helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 11:07:24 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-code-Members/Efficient-way-to-get-host-s-name-from-VM-vim-VirtualMachine/m-p/2918521#M65</guid>
      <dc:creator>FC86</dc:creator>
      <dc:date>2022-07-13T11:07:24Z</dc:date>
    </item>
  </channel>
</rss>

