VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

phisical nic _vlan_info_powercli

Hello Luc/all,

i have one standard switch info stored in variable in $s

pastedImage_0.png

if i do $s.nic it gave me me two physical nic

pastedImage_1.png

can yu please tell me how to get what vlans are allowed on these physical nics using powercli.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this.

You can eventually run the last part ('Retrieve stats') in a loop on an interval.

$esxName = 'MyEsx'

$vssName = 'MySwitch'

$esx = Get-VMHost -Name $esxName

$esxcli = Get-EsxCli -VMHost $esx -V2

$vss = $esxcli.network.vswitch.standard.list.Invoke() | where{$_.Name -eq $vssName}

# Activate stats

$vss.Uplinks | %{

    $sStat = @{

        nicname = $_

        enabled = $true

    }

    $esxcli.network.nic.vlan.stats.set.Invoke($sStat)

}

# Retrieve stats

foreach($pnic in $vss.Uplinks){

    $gStat = @{

        nicname = $pnic

    }

    $esxcli.network.nic.vlan.stats.get.Invoke($gStat) | Select -Property @{N='pNIC';E={$pnic}},*

}


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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

Do you mean "allowed" or "defined"?

For allowed one would have to query the physical switch via CDP (or similar).

For defined, one would need to look at all the portgroups defined on those pnics.


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

allowed.

actually i moved one of the esxi hostfrom one vcenter to another .

instead of importing that distributed switch im creating required port groups on standrd switch (though not good practice but tesst environamet)

right now webclient not working so thought of checking all allowed on those phy nic.(using powercli)

there is way to check through esxcli (by ssh to esxi)

i want to use below using powercli.

Network Troubleshooting Using ESXCLI 5.1 - VMware vSphere Blog

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do something like this

$esxName = 'MyEsx'

$vssName = 'MySwitch'

$esx = Get-VMHost -Name $esxName

$esxcli = Get-EsxCli -VMHost $esx -V2

$esxcli.network.vswitch.standard.portgroup.list.Invoke() |

where{$_.VirtualSwitch -eq $vssName} |

Select Name,VLANID


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Luc,

but very specifically i want to enable vlan stats and to get allowed vlan info  on both physical nic connected to vss.

so i tried

following  how to use these methods do i need to put .invoke() or what is the correct syntax .

pastedImage_0.png

esxi shell equvalent are

esxcli network nic vlan stats set -e true -n vmnic2

and then run the following command to retrieve all VLAN stats for that given vmnic interface (replace with the vmnic of choice):

esxcli network nic vlan stats get -n vmnic2

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this.

You can eventually run the last part ('Retrieve stats') in a loop on an interval.

$esxName = 'MyEsx'

$vssName = 'MySwitch'

$esx = Get-VMHost -Name $esxName

$esxcli = Get-EsxCli -VMHost $esx -V2

$vss = $esxcli.network.vswitch.standard.list.Invoke() | where{$_.Name -eq $vssName}

# Activate stats

$vss.Uplinks | %{

    $sStat = @{

        nicname = $_

        enabled = $true

    }

    $esxcli.network.nic.vlan.stats.set.Invoke($sStat)

}

# Retrieve stats

foreach($pnic in $vss.Uplinks){

    $gStat = @{

        nicname = $pnic

    }

    $esxcli.network.nic.vlan.stats.get.Invoke($gStat) | Select -Property @{N='pNIC';E={$pnic}},*

}


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

jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Luc. it worked fine.

i find a series of vlans per vmnic .

that means all these vlans are allowed(not sure what you mean by defined earlier) and this vmnic is connected to trunk port of the physical switch . is this correct?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

With "defined" I mean what is defined on the trunk on the physical switch.

When CDP is enabled, you can query the switch.

Yes, your assumption is correct.


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

cdp is enabled but by query the switch you mean by using powercli or through webclient .

also is there any way i can get what is configured inside guest os (like ip,defaultgatewat,dns)

i was able to find ip address by using $vm.guest.....nested property but not other info.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The network settings inside the guest OS are not all available through PowerCLI directly.

You will have to query inside the guest OS, for example through Invoke-VMScript.

You can query CDP info through PowerCLI.

Have a look at Jonathan's post Obtaining CDP info via PowerCLI


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks iam checking it.

Reply
0 Kudos