Skip to main content

Script to Collect the BMC/OOB/CIMC IP Address of ESXi hosts connected to vCenter

 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

Popular posts from this blog

How to find the physical switch port details from esxcli?

 This article will help you to get the details of the physical switch port details of  ESXi uplinks. Step 1: Login to the ESXi host using root user/ SSO User. Step 2: Enter the below command into the terminal.   vim-cmd hostsvc/net/query_networkhint | grep 'portId\|devId\|vmnic' Output will show the details of the associated physical switch. Note: CDP, LLDP has to be enabled on physical switch. This information is needed when you end up in a troubleshooting session with network team for physical uplinks down/inconsistency of traffic.

JobQueue is full in iDRAC and unable to upgrade firmware??

  Hello There, I was working recently on upgrading the firmware for Dell Power Edge servers due a requirement. As usual, I did the download of the necessary firmware update file and uploaded it in the iDRAC and started the upgrade. Waited for couple of minutes, If I can say, it was almost 15 minutes without any progress. I tried to check the log/job queue in the iDRAC and found it was full of old entries and I tried clearing it but found no option. Later after findings, I managed to find a command which clears the jobqueue, and below is the command I used after logging into iDRAC via SSH. racadm jobqueue delete -i JID_CLEARALL_FORCE Once the above command was executed, I tried to login to iDRAC and check the job queue and found everything was cleared. Whats next?? Tried uploading the file again and then managed to successfully update the firmware.

Renew SSL Certificate for vCloud Director 10.4

Hello There, I would like to give credit for this article to my colleague Muhannad S. Aljaghthami who worked on this task and gave us full insight on how to do. Now lets talk about replacing an expired/ about to expire SSL certificate for the vCloud Director application which is hosted on internet. Prerequisites: Digicert Certificate utility for windows.  Putty/Mobaxterm application for SSH to vCD cells. Winscp to transfer the files to vCD cells. SSH access should be validated on vCD Cells Backup tool to take a backup of vCD cells. Versions & products used while writing this article: vCloud Director 10.4 NSX AVI 22.1.1 Step by step procedure: Initiated a CSR request using Digicert utility for windows and shared the CSR with the team who manages the SSL certificates.  Post submission of CSR,we received the root & SSL certificate for our vCloud Director URL. Using the Digicert utility, we have extracted the pfx file and key file, sample screenshot below.     No...