SCharchouf
Hot Shot
Hot Shot

esxcli network nic list

Jump to solution

Hello community Smiley Happy

I need assistance in order to collect esxcli network nic list via script from all ESXi by connecting via vCenter is that possible?

the idea is really to have all statiques from all ESXi in order to identify a big issue in network

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this


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

View solution in original post

19 Replies
LucD
Leadership
Leadership

Yes, you could do something like this

Get-VMHost -PipelineVariable esx | ForEach-Object -Process {

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

    $esxcli.network.nic.list.Invoke() |

    Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru

}


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

SCharchouf
Hot Shot
Hot Shot

I created the below scripts in order to get stats per vCenters, in one Excel file and separate sheet is that correct?

# vCenter Login

#$vCUser="Login"

#$vCPass="password"

# LIST OF vCenter

$vCenterIP = "vcenter1","vcenter2","vcenter3"

$StartTime = Get-Date

$dateF = Get-Date -UFormat "%d-%b-%Y_%H-%M-%S"

# Connection to vCenter

foreach ($IPAddress in $vCenterIP) {

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Requires -Modules ImportExcel

$fileName = ".\ALL_vCenter_NIC_Stats_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"

$reportNICStats = @()

$esxhosts = Get-VMHost

foreach ($esx in $esxhosts) {

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

  

                  $reportNICStats += $esxcli.network.nic.list.Invoke() |

                  ForEach-Object -Process

                  Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru

}

$reportNic | Export-Excel -Path $fileName -WorksheetName 'NIC STATS'

0 Kudos
LucD
Leadership
Leadership

The WorksheetName is the same for each vCenter.


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Ooops, it should be different based on venter name

0 Kudos
LucD
Leadership
Leadership

You could use

$reportNic | Export-Excel -Path $fileName -WorksheetName "$IPAddress - NIC STATS"


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

got the below error message:

ForEach-Object : Missing an argument for parameter 'Process'. Specify a parameter of type 'System.Management.Automation.ScriptBlock[]' and try again.

At .\NIC_STATS\NIC_STATS.ps1:31 char:34

+                   ForEach-Object -Process

+                                  ~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [ForEach-Object], ParameterBindingException

    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.ForEachObjectCommand

cmdlet Add-Member at command pipeline position 1

Supply values for the following parameters:

InputObject:

0 Kudos
LucD
Leadership
Leadership

It looks like you forgot the curly brace at the end of the Foreach-Object line.


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

SCharchouf
Hot Shot
Hot Shot

thankis LucD Smiley Happy

now this is what I get

cmdlet Add-Member at command pipeline position 1

Supply values for the following parameters:

InputObject:

------------------------>Script--------------------------------------

$StartTime = Get-Date

$dateF = Get-Date -UFormat "%d-%b-%Y_%H-%M-%S"

# Connection to vCenter

foreach ($IPAddress in $vCenterIP) {

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Requires -Modules ImportExcel

$fileName = ".\ALL_vCenter_NIC_Stats_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"

$reportNICStats = @()

$esxhosts = Get-VMHost

foreach ($esx in $esxhosts) {

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

  

                  $reportNICStats += $esxcli.network.nic.list.Invoke() |

                  ForEach-Object -Process {

                  Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru

}

}

$reportNic | Export-Excel -Path $fileName -WorksheetName "$IPAddress - NIC STATS"

0 Kudos
LucD
Leadership
Leadership

You didn't copy the code I posted earlier correctly.

There is a pipeline symbol at the end of the 1st line

    $esxcli.network.nic.list.Invoke() |

    Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

the output is empty, the xlsx file generated but no data filled , strange

0 Kudos
LucD
Leadership
Leadership

Can you attach the script you are currently using?


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

# vCenter Login

$vCUser="login"

$vCPass="password"

# LIST OF vCenter

$vCenterIP = "vcenter1","vcenter2","vcenter3","vcenter4","vcenter5"

$StartTime = Get-Date

$dateF = Get-Date -UFormat "%d-%b-%Y_%H-%M-%S"

# Connection to vCenter

foreach ($IPAddress in $vCenterIP) {

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Requires -Modules ImportExcel

$fileName = ".\NIC_STATS\ALL_vCenter_NIC_Stats_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"

$reportNICStats = @()

$esxhosts = Get-VMHost

foreach ($esx in $esxhosts) {

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

  

                  $reportNICStats += $esxcli.network.nic.list.Invoke() |

                  ForEach-Object -Process {

                  $esxcli.network.nic.list.Invoke() |

                  Add-Member -MemberType NoteProperty -Name VMHost -Value $esx.Name -PassThru

}

}

$reportNic | Export-Excel -Path $fileName -WorksheetName "$IPAddress - NIC STATS"

0 Kudos
LucD
Leadership
Leadership

I mean 'Attach' as a file.

The option is bottom right of the edit window


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Attached

0 Kudos
LucD
Leadership
Leadership

A Word document is even worse :smileycry:

I had a quick look at your code and there are some issues in there.

Try this attached version.


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Sorry, as I used my phone to attach the script, I'm really sorry :smileyblush::smileyblush:

The report is Ok and I have a question, for this same script can we get NIC statistics for vmnic?

the idea is to verify all vmnics stats especially the below details :

Total receive errors

  Receive length errors

  Receive over errors

  Receive CRC errors

  Receive frame errors

  Receive FIFO errors

  Receive missed errors

  Total transmit errors

  Transmit aborted errors

  Transmit carrier errors

  Transmit FIFO errors

  Transmit heartbeat errors

  Transmit window errors

0 Kudos
LucD
Leadership
Leadership

Try something like this


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

View solution in original post

SCharchouf
Hot Shot
Hot Shot

Thanks LuCD Smiley Happy you are the best Smiley Happy

Just one more thing, in Excel there's a lot of date like this

8,06472E+11

can I do the change via script or in Excel directly?

0 Kudos
LucD
Leadership
Leadership

You can do the same with the Set-ExcelRange cmdlet as what you can do in Excel.

See for example that Databar.ps1 example in the ImportExcel repo.


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

0 Kudos