VMware Cloud Community
GordonPM
Enthusiast
Enthusiast
Jump to solution

How to find ESX hostnames from distributed switch query

I seem to be going round in circles on this one.

Is there an easy way to to query the vDS and return the hostnames of the connected ESX hosts?

I can get it using Moref via the following kind of thing:

Get-VDSwitch | ForEach {

    $SwMORefs = $_.ExtensionData.Config.host.config.host.value

    $SwitchName = $_.Name

    $SwitchName

    ForEach ($MR in $SwMORefs) {

        $AttachedHost = Get-VMHost | Where {$_.ExtensionData.MoRef -match $MR}

        $AttachedHost

    }

}

...but this seems a bit complex and slow?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Is this a bit faster?

foreach($vds in Get-VDSwitch){

   Get-View -Id $vds.ExtensionData.Config.host.config.host -Property Name |

  Select @{N='vdSwitch';E={$vds.Name}},Name

}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Is this a bit faster?

foreach($vds in Get-VDSwitch){

   Get-View -Id $vds.ExtensionData.Config.host.config.host -Property Name |

  Select @{N='vdSwitch';E={$vds.Name}},Name

}


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

0 Kudos
GordonPM
Enthusiast
Enthusiast
Jump to solution

Perfect thank you, I really need to start using Get-View a lot more.

0 Kudos