Hello community
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
Try something like this
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, you could do something like this
$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
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'
The WorksheetName is the same for each vCenter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ooops, it should be different based on venter name
You could use
$reportNic | Export-Excel -Path $fileName -WorksheetName "$IPAddress - NIC STATS"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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:
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
thankis LucD
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"
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
the output is empty, the xlsx file generated but no data filled , strange
Can you attach the script you are currently using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
# 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"
I mean 'Attach' as a file.
The option is bottom right of the edit window
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
Thanks LuCD you are the best
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?
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