VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

vmnic Associated with vSwitch Details

Hi All,

I have written below script for getting host vSwitch Details and script works fine.

Get-VirtualPortGroup | select @{N='HostName';E={(Get-View -ID $_.VMHostID | select -expandproperty Name)}},VirtualSwitchName,Name,VLANId

Is there any way that we can get vmnic associated with vSwitch

if vSwitch1 is having 2 vmnic then it needs to print like

vmnic0 vSwitch1

vmnic1 vSwitch1

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

foreach($pg in Get-VirtualPortGroup -Standard){

    $pg.VirtualSwitch.Nic |

    Select @{N='VMHost';E={$pg.VirtualSwitch.VMHost.Name}},

        @{N='vSwitch';E={$pg.VirtualSwitch.Name}},

        @{N='Portgroup';E={$pg.Name}},

        @{N='VLanId';E={$pg.VLanId}},

        @{N='pNIC';E={$_}}

}


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

View solution in original post

0 Kudos
3 Replies
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi All,

Can someone suggest me the right way of getting this report.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

foreach($pg in Get-VirtualPortGroup -Standard){

    $pg.VirtualSwitch.Nic |

    Select @{N='VMHost';E={$pg.VirtualSwitch.VMHost.Name}},

        @{N='vSwitch';E={$pg.VirtualSwitch.Name}},

        @{N='Portgroup';E={$pg.Name}},

        @{N='VLanId';E={$pg.VLanId}},

        @{N='pNIC';E={$_}}

}


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Thanks Lucd, Script works fine.

0 Kudos