VMware Cloud Community
mlichsteintwc
Enthusiast
Enthusiast

Using get-view to get host management IP?

Hi

Is there a way to get the management IPs of all hosts in a particular cluster using get-view? I'm trying to speed this up:

get-cluster $vmware_cluster | Get-VMHost | Get-VMHostNetworkAdapter -VMKernel | ? {$_.Name -eq "vmk0"} | Select-Object IP

I thought I was headed in the right direction with:

get-view -ViewType HostSystem -Property Name -Searchroot $vmware_cluster.ExtensionData.MoRef

but I don't see how to pull network info out of that.

Thanks!

2 Replies
mlichsteintwc
Enthusiast
Enthusiast

I think I figured it out:

$vmware_cluster = "my-cluster"

$host_ips = [System.Collections.ArrayList]@()

foreach ($esx in (Get-View -ViewType HostSystem -Property Name,Config.Network.Vnic -SearchRoot (Get-cluster $vmware_cluster).Id)){

  foreach ($vnic in ($esx.Config.Network.Vnic | where {$_.Device -eq "vmk0"})){

      $vmk = $vnic.Spec.Ip.IpAddress

      $host_ips.Add($vmk) > $null

  }

}

0 Kudos
LucD
Leadership
Leadership

That will work, provided your Management service always runs on vmk0, and only on vmk0.
A better way,imho, would be to look at all vmkernel entries, check the ones that have the Managment service running, and return those IP(s)


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