I have created the below script and I have some issue, I need assistance to correcte the same
# vCenter Login
$vCUser="LOGIN"
$vCPass="password"
# LIST OF vCenter
$vCenterIP = ""VCENTER","VCENTER1",,"VCENTER2","VCENTER3""
# Connection to vCenter
foreach ($IPAddress in $vCenterIP){
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
#Requires -Modules ImportExcel
$fileName = '.\PowerShell_Script\report_Nic_HBA\ALL_vCenter_Firmware_Report.xlsx'
$reportNic = @()
$reportHba = @()
foreach ($esx in $esxhosts) {
$esxcli = Get-EsxCli -VMHost $esx -V2
foreach ($nic in $esxcli.network.nic.list()) {
$reportNic += $Esxcli.network.nic.get.Invoke(@{nicname = $nic.Name}).driverinfo |
Select @{N = "HostName"; E = {$esxcli.VMHost.Name}},
@{N = "NICName"; E = {$nic.Name}},
@{N = "NICDriver"; E = {$NicInfo.Driver}},
@{n = "NICDriver-Version"; E = {$NicInfo.Version}},
@{N = "NICFirmware-Version"; E = {$NicInfo.FirmWareVersion}} #|Export-Csv -Path .\PowerShell_Script\report_Nic_HBA\NIC-Drive-FW.csv
}
$reportHba += $esxcli.Storage.san.fc.list.Invoke()|
select @{N = 'HostName'; E = {$esxcli.VMHost.Name}},
Adapter, DriverName, DriverVersion, FirmwareVersion, hardwareVersion, PortState
}
$reportNic | Export-Csv -Path $fileName -WorksheetName 'Nic'
$reportHba | Export-Csv -Path $fileName -WorksheetName 'HBA'
-------------------------------------------------------------------------------------
Issue
-------------------------------------------------------------------------------------
1-each time when I run the script I need to put LOGIN & password despite the same is in the script
2- when I run the script I got the below error
Export-Csv : A parameter cannot be found that matches parameter name 'WorksheetName'.
At .\PowerShell_Script\ALL_vCenter_Firmware_Driver_Report_V2.ps1:56 char:41
+ $reportNic | Export-Csv -Path $fileName -WorksheetName 'Nic'
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : A parameter cannot be found that matches parameter name 'WorksheetName'.
At .\PowerShell_Script\ALL_vCenter_Firmware_Driver_Report_V2.ps1:58 char:41
+ $reportHba | Export-Csv -Path $fileName -WorksheetName 'HBA'
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
Does it prompt you for each vCenter or only one of them?
The cmdlet is not Export-Csv but Export-Excel.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD the cmdlet is changed and no error
regarding connectivity to vcenter yep it asked for each vcenter
the output is blank not sure why
Your array fo vCenter names has too many double quotes, which will make it into 1 string.
Try with
$vCenterIP = "VCENTER","VCENTER1",,"VCENTER2","VCENTER3"
Did you check if there is anything in the arrays?
Were the vCenter connections established? Did you check $global:defaultVIservers?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
now it's connecting fine
unfortunately the report is empty
Where do you initialise $esxhosts?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yep you are right I used it thinking that info will be collected from esxi when it's connected to vcenter
So everything is working now?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No
I'm trying to correct the script
Isn't that just adding this line before the foreach?
$esxhosts = Get-VMHost
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I added it and below is the script
# vCenter Login
$vCUser="login"
$vCPass="password"
# LIST OF vCenter
$vCenterIP = "VC","VC1"
# Connection to vCenter
foreach ($IPAddress in $vCenterIP){
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
#Requires -Modules ImportExcel
$fileName = '.\report_Nic_HBA\ALL_vCenter_Firmware_Report.xlsx'
$reportNic = @()
$reportHba = @()
$esxhosts = Get-VMHost
foreach ($esx in $esxhosts) {
$esxcli = Get-EsxCli -VMHost $esx -V2
foreach ($nic in $esxcli.network.nic.list()) {
$reportNic += $Esxcli.network.nic.get.Invoke(@{nicname = $nic.Name}).driverinfo |
Select @{N = "HostName"; E = {$esxcli.VMHost.Name}},
@{N = "NICName"; E = {$nic.Name}},
@{N = "NICDriver"; E = {$NicInfo.Driver}},
@{n = "NICDriver-Version"; E = {$NicInfo.Version}},
@{N = "NICFirmware-Version"; E = {$NicInfo.FirmWareVersion}} #|Export-Csv -Path .\report_Nic_HBA\NIC-Drive-FW.csv
}
$reportHba += $esxcli.Storage.san.fc.list.Invoke()|
select @{N = 'HostName'; E = {$esxcli.VMHost.Name}},
Adapter, DriverName, DriverVersion, FirmwareVersion, hardwareVersion, PortState
}
$reportNic | Export-Excel -Path $fileName -WorksheetName 'Nic'
$reportHba | Export-Excel -Path $fileName -WorksheetName 'HBA'
--------------------------------------------------------------------
Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.EsxCli.EsxCliElementImpl] does not contain a method named 'list'.
At .\ALL_vCenter_Firmware_Driver_Report_V2.ps1:31 char:21
+ foreach ($nic in $esxcli.network.nic.list()) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (list:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
When you use the V2 switch on Get-EsxCli, you have to use the Invoke method.
foreach ($nic in $esxcli.network.nic.list.Invoke()) {
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Now it's much better, but I got a blank output for
NICDriver | NICDriver-Version | NICFirmware-Version |
for HBA report it's OK for some servers as they have a HBA card not like blade servers with Converged Card
Later I will try to add server type to script in order to seperate results
Isn't that what we handled in that other thread of yours?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yep exactly
Unfortunately they asked me to separate results in one file with worksheet
for that I tried to create a new script based on what I have in other thread
as we have blade servers using Converged Network Card and DL server which they uses embedded network card and HBA card
so for sure the the drivers is not the same firmware also
all this stuff will be used for migration reason
You are using the wrong properties.
Replace those lines with
@{n = "NICDriver-Version"; E = { $Nic.DriverInfo.Version } },
@{N = "NICFirmware-Version"; E = { $Nic.DriverInfo.FirmWareVersion } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference