VMware Cloud Community
esxi1979
Expert
Expert

VM vlan id in Std Switch & VDS

Hi,

Get-VM xxx| Select Name,

    @{N="IP addr";E={[string]::Join(',',$_.Guest.IPAddress)}},

    @{N="MAC addr";E={[string]::Join(',',($_.Guest.Nics | %{$_.MacAddress}))}},

    @{N="NIC type";E={[string]::Join(',',($_.Guest.Nics | %{$_.Device.Type}))}},

    @{N="VLANid";E={(Get-VM $_ |Get-NetworkAdapter |select NetworkName  )}}

For Std switch this gives me no info for vlan id

Get-VM xxx| Get-NetworkAdapter gives all info well tho

------------------------ ****** ---------------------------------------- ****** -------------------------------

for VDS  same code above gives info well, but the name of vlan comes as , I would need the xxx in tho..

@{NetworkName=xxx}

Can some help ..

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try like this

Get-VM xxx | Select Name,

    @{N="IP addr";E={[string]::Join(',',$_.Guest.IPAddress)}},

    @{N="MAC addr";E={[string]::Join(',',($_.Guest.Nics | %{$_.MacAddress}))}},

    @{N="NIC type";E={[string]::Join(',',($_.Guest.Nics | %{$_.Device.Type}))}},

    @{N="VLANid";E={(Get-VM $_ |Get-NetworkAdapter |select -ExpandProperty NetworkName  )}}


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

0 Kudos
esxi1979
Expert
Expert

well it worked ... but taking generations to pull the info Smiley Wink

0 Kudos
AGerlitz
Contributor
Contributor

You can try modifying the last line in that script to read:


@{N="VLANid";E={($_.NetworkAdapters.NetworkName)}}

Your environment may be different but it made this faster for me.

0 Kudos