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.

System Recovery Partition Disk Blocks The Extension of Windows Disk - Sysprep Issues

Requirement : Windows Activated Template on vCenter  Issue : After the windows is installed, system recovery partition end up created next to windows disk.  Resolution Credit : Mohammed Junaid Ahmed                           Resolution :  1) Create a VM using standard procedure on vCenter  2) Power ON the VM and follow below screen instructions  Click Next   Click on ' Repair your computer '  Click on Troubleshoot       Click on Command Prompt     You should see the command prompt Begin with Diskpart   Click Turn off your PC Restart your computer and continue windows installation, and you will see the disk partitions as below

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...