Hello Luc/all,
i have one standard switch info stored in variable in $s
if i do $s.nic it gave me me two physical nic
can yu please tell me how to get what vlans are allowed on these physical nics using powercli.
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
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
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
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
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 .
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
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
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?
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
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.
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
thnaks iam checking it.