Requirement:
We needed to collect all the iDRAC/ILO/CIMC/OOB/BMC IPs of the ESXi host connected to vCenter
Note: Create a directory and update the path.
Script:
# Prompt for vCenter
$vcenter = Read-Host "Enter vCenter IP or FQDN"
$cred = Get-Credential
# Output file
$OutputPath = "C:\Users\TestUser\Documents\ESXi_Full_Report.csv"
# Connect
Connect-VIServer -Server $vcenter -Credential $cred -WarningAction SilentlyContinue
Write-Host "Connected to vCenter. Gathering data..." -ForegroundColor Green
$report = @()
$vmhosts = Get-VMHost
foreach ($vmhost in $vmhosts) {
Write-Host "Processing host: $($vmhost.Name)" -ForegroundColor Cyan
$view = Get-View $vmhost.Id
# --- SERIAL NUMBER LOGIC ---
$serial = $view.Hardware.SystemInfo.SerialNumber
if (-not $serial) {
foreach ($id in $view.Summary.Hardware.OtherIdentifyingInfo) {
if ($id.IdentifierType.Key -match "Serial|ServiceTag") {
$serial = $id.IdentifierValue
break
}
}
}
# --- NETWORK / LLDP ---
$networkSystem = Get-View $vmhost.ExtensionData.ConfigManager.NetworkSystem
$physicalNics = $vmhost.ExtensionData.Config.Network.Pnic
foreach ($pnic in $physicalNics) {
$networkHint = $null
try {
$networkHint = $networkSystem.QueryNetworkHint($pnic.Device)
}
catch {
Write-Warning "Failed LLDP for $($vmhost.Name) - $($pnic.Device)"
continue
}
if ($networkHint) {
foreach ($hint in $networkHint) {
if ($hint.LldpInfo) {
$lldp = $hint.LldpInfo
$mgmtIP = (Get-VMHostNetworkAdapter -VMHost $vmhost |
Where-Object {$_.ManagementTrafficEnabled})[0].IP
$entry = [PSCustomObject]@{
# --- Host Info ---
HostName = $vmhost.Name
ManagementIP = $mgmtIP
Vendor = $view.Summary.Hardware.Vendor
Model = $view.Summary.Hardware.Model
SerialNumber = $serial
CPUModel = $view.Summary.Hardware.CpuModel
CpuCores = $view.Summary.Hardware.NumCpuCores
MemoryGB = [math]::Round($view.Summary.Hardware.MemorySize / 1GB, 2)
# --- NIC Info ---
PhysicalNIC = $pnic.Device
# --- LLDP Info ---
LLDP_ChassisID = $lldp.ChassisId
LLDP_PortID = $lldp.PortId
LLDP_SystemName = ($lldp.Parameter | Where-Object {$_.Key -eq "System Name"}).Value
LLDP_PortDesc = ($lldp.Parameter | Where-Object {$_.Key -eq "Port Description"}).Value
LLDP_MgmtAddr = ($lldp.Parameter | Where-Object {$_.Key -eq "Management Address"}).Value
}
$report += $entry
}
}
}
}
}
# Output
if ($report.Count -gt 0) {
$report | Export-Csv -Path $OutputPath -NoTypeInformation
Write-Host "Report exported to $OutputPath" -ForegroundColor Green
} else {
Write-Warning "No data collected."
}
Disconnect-VIServer -Confirm:$false
Write-Host "Done."
1) Save the script as ps1.
2) Run from powershell.
3) Provide credentials for vCenter
4) Find the output from the provided path.
Comments
Post a Comment