I've just managed to get the port stats by manually entering the PortID, using $esxcli.network.port.stats.get.Invoke(@{portid = '33554434'}).
But as I mentioned, I'd like to be able to focus only on PortIDs of vmnics.
It is not a full replication of the net-stats command, but besides the fact that you don't have the PortNum, there is no statistical data for the vmnic afaik.
Try with one of the PortNum returned by net-stats for one of the vmnic.
You can get the statistics for the VMKernel and the VM connected.
That can be done something like this
$esxcli = Get-EsxCli -VMHost $esxName -V2
$esxcli.network.ip.interface.list.Invoke() |
ForEach-Object -Process {
$vmk = $_
$esxcli.network.port.stats.get.Invoke(@{portid=$vmk.PortID}) |
Add-Member -MemberType NoteProperty -Name ClientName -Value $vmk.Name -PassThru |
Add-Member -MemberType NoteProperty -Name SwitchName -Value $vmk.VDSName -PassThru |
Add-Member -MemberType NoteProperty -Name PortNum -Value $vmk.PortID -PassThru
}
$esxcli.network.vm.list.Invoke() |
ForEach-Object -Process {
$vm = $_
$filter = $esxcli.network.vm.port.list.Invoke(@{worldid=$vm.WorldID})
$esxcli.network.port.stats.get.Invoke(@{portid=$filter.PortID}) |
Add-Member -MemberType NoteProperty -Name ClientName -Value $vm.Name -PassThru |
Add-Member -MemberType NoteProperty -Name SwitchName -Value $filter.vSwitch -PassThru |
Add-Member -MemberType NoteProperty -Name PortNum -Value $filter.PortID -PassThru
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
With one of your scripts using Posh-SSH, I've been able to get the PortID of vmnics
$esxName = 'MyEsx'
$esx = Get-VMHost -Name $esxName
$esxcli = Get-EsxCli -VMHost $esx -V2
$cmdsub = @'
net-stats -l | grep -i vmnic | awk '{print $1}';
'@
$secPswd = ConvertTo-SecureString 'S@curePass!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('root', $secPswd)
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
$PortIDs = Invoke-SSHCommand -SSHSession $session -Command $cmdSub | Select -ExpandProperty Output
Foreach ($portid in $PortIDs){
$esxcli.network.port.stats.get.Invoke(@{portid = "$PortID"})
}
Remove-SSHSession -SSHSession $session | Out-Null
It still lacks a little bit of info such as the hostname and the VMNIC. Would you be able to help me optimize the above snippet to run against multiple hosts, therefore a group of hosts in a cluster? It'd be useful to have the script report the vmnic stats that are online/UP from all the hosts in the cluster.
I'm not sure how you got that result, for me that is not working.
I'm on an ESXi v7 node.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
May be it makes a difference with the ESXi version. But does this make sense to you?
I can only do that with the portId of a VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference