Hi All,
I need to get some hardware and driver, firmware information using the below PowerCLI, however, some of the columns in the.CSV file is not working like below are empty:
IPAddress | Manufacturer | ProcessorType | BIOS version | HBA Model | Driver |
This is the code I am using:
$vmhosts = Get-Datacenter | Get-VMHost
$report = @()
foreach( $ESXHost in $vmhosts) {
$HWModel = Get-VMHost $ESXHost
$esxcli = Get-EsxCli -vmhost $ESXHost
$info = $esxcli.network.nic.get("vmnic0")
$elxnet = $esxcli.software.vib.list() | Where-Object { $_.name -eq "elxnet"}
$lpfc = $esxcli.system.module.list() | Where-Object {$_.Name -eq '*'}
if($lpfc){
$lpfc = $esxcli.system.module.get("*")
}
$report += $info |
Select-Object @{N="Hostname"; E={$ESXHost.Name}},
@{N="IPAddress"; E={($_ | Get-VMHostNetwork).VirtualNic | Where-Object {$_.ManagementTrafficEnabled} | Select-Object -ExpandProperty IP}},
Manufacturer,
ProcessorType,
@{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},
@{N="Hardware-Model"; E={$HWModel.Model}},
@{N="Adapter-Firmware"; E={$_.DriverInfo.FirmwareVersion}},
@{N="Network-Driver"; E={$_.DriverInfo.Version}},
@{N="FC-Driver"; E={$elxnet.version.substring(0,14)}},
@{N="HBA Model";E={($_ | get-vmhosthba | select-object -ExpandProperty Model) -join ", "}},
@{N="Driver";E={($_ | get-vmhosthba | select-object -ExpandProperty Driver) -join ", "}}
@{N='HBA-Module';E={$lpfc.Module}},
@{N='HBA-Version';E={$lpfc.Version}}
}
$report | Export-Csv -Path $ResultFile -NoTypeInformation
ii $ResultFile
There is no error in the console session:
Name Value
---- -----
N HBA-Module
E $lpfc.Module
N HBA-Version
E $lpfc.Version
N HBA-Module
E $lpfc.Module
N HBA-Version
E $lpfc.Version
Thank you in advance.
The funny property names is due to the comma that is missing at a line in the Select.
Also the properties should be derived from the $ESXHost object, only the Firmware and Driver comes from the $info object.
Try like this
$vmhosts = Get-Datacenter | Get-VMHost
$report = @()
foreach ( $ESXHost in $vmhosts)
{
$HWModel = Get-VMHost $ESXHost
$esxcli = Get-EsxCli -vmhost $ESXHost
$info = $esxcli.network.nic.get("vmnic0")
$elxnet = $esxcli.software.vib.list() | Where-Object { $_.name -eq "elxnet" }
$lpfc = $esxcli.system.module.list() | Where-Object { $_.Name -eq '*' }
if ($lpfc)
{
$lpfc = $esxcli.system.module.get("*")
}
$report += $ESXHost |
Select-Object @{N = "Hostname"; E = { $_.Name } },
@{N = "IPAddress"; E = { ($_ | Get-VMHostNetwork).VirtualNic | Where-Object { $_.ManagementTrafficEnabled } | Select-Object -ExpandProperty IP } },
Manufacturer,
ProcessorType,
@{N = "BIOS version"; E = { $_.ExtensionData.Hardware.BiosInfo.BiosVersion } },
@{N = "Hardware-Model"; E = { $HWModel.Model } },
@{N = "Adapter-Firmware"; E = { $info.DriverInfo.FirmwareVersion } },
@{N = "Network-Driver"; E = { $info.DriverInfo.Version } },
@{N = "FC-Driver"; E = { $elxnet.version.substring(0, 14) } },
@{N = "HBA Model"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Model) -join ", " } },
@{N = "Driver"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Driver) -join ", " } },
@{N = 'HBA-Module'; E = { $lpfc.Module } },
@{N = 'HBA-Version'; E = { $lpfc.Version } }
}
$report | Export-Csv -Path $ResultFile -NoTypeInformation
---------------------------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The funny property names is due to the comma that is missing at a line in the Select.
Also the properties should be derived from the $ESXHost object, only the Firmware and Driver comes from the $info object.
Try like this
$vmhosts = Get-Datacenter | Get-VMHost
$report = @()
foreach ( $ESXHost in $vmhosts)
{
$HWModel = Get-VMHost $ESXHost
$esxcli = Get-EsxCli -vmhost $ESXHost
$info = $esxcli.network.nic.get("vmnic0")
$elxnet = $esxcli.software.vib.list() | Where-Object { $_.name -eq "elxnet" }
$lpfc = $esxcli.system.module.list() | Where-Object { $_.Name -eq '*' }
if ($lpfc)
{
$lpfc = $esxcli.system.module.get("*")
}
$report += $ESXHost |
Select-Object @{N = "Hostname"; E = { $_.Name } },
@{N = "IPAddress"; E = { ($_ | Get-VMHostNetwork).VirtualNic | Where-Object { $_.ManagementTrafficEnabled } | Select-Object -ExpandProperty IP } },
Manufacturer,
ProcessorType,
@{N = "BIOS version"; E = { $_.ExtensionData.Hardware.BiosInfo.BiosVersion } },
@{N = "Hardware-Model"; E = { $HWModel.Model } },
@{N = "Adapter-Firmware"; E = { $info.DriverInfo.FirmwareVersion } },
@{N = "Network-Driver"; E = { $info.DriverInfo.Version } },
@{N = "FC-Driver"; E = { $elxnet.version.substring(0, 14) } },
@{N = "HBA Model"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Model) -join ", " } },
@{N = "Driver"; E = { ($_ | get-vmhosthba | select-object -ExpandProperty Driver) -join ", " } },
@{N = 'HBA-Module'; E = { $lpfc.Module } },
@{N = 'HBA-Version'; E = { $lpfc.Version } }
}
$report | Export-Csv -Path $ResultFile -NoTypeInformation
---------------------------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Many thanks, Luc, you're always be very helpful.