VMware Cloud Community
piercj2
Enthusiast
Enthusiast
Jump to solution

ESXi Host EOL report

Hi All,

I've created the below to generate a report containing End of Life / End of Support information for approx 2000 ESXi Hosts, spread across multiple vCenters.

The report works to a point. I've just noticed that it's returning the same Serial numbers for a lot of the ESXi Hosts, these should all be unique. I've also noticed that the model numbers are not always correct either. If i run the script against individual ESXi Hosts, the data returned is correct.

The script runs without error so i don't understand why duplicate/incorrect information is being returned for some of the Servers.

Could it be that i don't have enough memory/cpu on the server that's running the script ?

Should i be using Get-View instead of Get-Esxcli to optimize the data collection ?

Should i be setting each variable to null before moving to the next ESXi Host (seems wasteful)

$cred = Get-Credential 'username@company.com'

$vCenters = @(

    "vc1.company.com"

    "vc2.company.com"

    "vc3.company.com"

    "vc4.company.com"

    )

Connect-VIServer -Server $vCenters -Credential $cred -ErrorAction SilentlyContinue

# Server model to EOL date mappings, edit to add/correct dates

$vmHostModelEolMapping = @{

    "UCS-C210" = "2020/Jun"

    "UCS-C220" = "2020/Jun"

    "UCS-C240" = "2018/Aug"

    "UCS-C420" = "2017/Jan"

    "PowerEdge R630" = "2018/May"

    "PowerEdge R710" = "2016/May"

    "PowerEdge R730xd" = "2018/May"

    "PowerEdge R900"  = "2015/Jul"

    "PowerEdge R910" = "2015/Mar"

    }

# Collect Server details

$results = @()

foreach ($vmHost in Get-VMHost) {

    $esxcli = Get-EsxCli -vmhost $vmHost.name -V2 -ErrorAction SilentlyContinue

    $vcName = [System.Net.Dns]::GetHostEntry((get-view $vmHost -ErrorAction SilentlyContinue).summary.managementserverip).HostName

    $vmHostName = $vmHost.Name

    $vmHostVendor = $esxcli.hardware.platform.get.invoke().VendorName

    $vmHostModel = $esxcli.hardware.platform.get.invoke().ProductName

    $vmHostSerial = $esxcli.hardware.platform.get.invoke().SerialNumber

    $EolDate = "Unknown"

    if ($vmHostModelEolMapping.ContainsKey($vmHostModel)){

        $EolDate = $vmHostModelEolMapping[$vmHostModel]

        }

    $prop = [pscustomobject] @{

            vCenter = $vcName

            "ESXi Host Name" = $vmHostName

            Vendor = $vmHostVendor

            Model = $vmHostModel

            Serial = $vmHostSerial

            EOL = $EolDate

    }

    $results+=$prop

}

$results | Sort-Object vCenter,"ESXi Host Name" | Export-Csv -path c:\Temp\EOLreport.csv

Tags (3)
20 Replies
LucD
Leadership
Leadership
Jump to solution

My bad, the PipelineVariable on a Foreach-Object doesn't work that way.

Try with this version

# login to vCenter(s) - use CTRL to select multiple vCenters

$cred = Get-Credential -Message "  ***********  Enter vCenter Credentials  ***********"


$vCenters = @(

    "vc1.company.com"

    "vc2.company.com"

    "vc3.company.com"

    "vc4.company.com"

    "vc5.company.com"

    )


$selectedVC = $vCenters | Out-GridView -Title "  ***  vCenter Listing - Select required vCenter(s)  ***" -OutputMode Multiple

Connect-VIServer -Server $selectedVC -Credential $cred -ErrorAction SilentlyContinue

# Server model to EOL date mappings, edit to add/correct dates

$vmHostModelEolMapping = @{

    # Cisco Servers

    "B230-BASE-M2"      = "2020/Jun"

    "C260-BASE-2646"    = "2020/Jun"

    "UCSB-B200-M4"      = "2024/Feb"

    "UCSC-BASE-M2-C460" = "2020/Apr"

    # Dell Servers

    "PowerEdge R630"    = "2018/May"

    "PowerEdge R640"    = "No EOL Published"

    "PowerEdge R710"    = "2016/May"

    # VxRails

    "VxRail E460"       = "2023/05"

    "VxRail P570F"      = "No EOL Published"

    }


# Install the ImportExcel module if not already installed and prepare Excel layout

If (!(Get-module -ListAvailable "ImportExcel")) {

    Find-Module -Name ImportExcel | Install-Module -Scope CurrentUser

    }


$ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks


$hash = @{

    Path = "C:\Temp\EOLreport.xlsx"

    Show = $true;

    AutoSize = $true;

    AutoFilter = $true;

    ConditionalText = $ContainsBlanks

    ShowPercent = $true;

    #HideSheet = "Sheet1";

    }


Remove-Item $hash.Path -ErrorAction Ignore


# Collect ESXi Host details for EOL Report

$vmHostAll = Get-VMHost

$i = 1


$vmHostAll | ForEach-Object -Process {

    $vmHost = $_

    Write-Progress -PercentComplete ($i / $vmHostAll.count * 100) -Activity "Generating Server End Of Life Report" -Status "Getting info on ($vmHost.Name))"

    $i++


    try {

        $esxcli = Get-EsxCli -vmhost $vmHost -V2 -ErrorAction Stop

        $platform = $esxcli.hardware.platform.get.invoke()

        }


    catch {

        Write-Host -ForegroundColor red  "Get-EsxCli failed for $($vmHost.Name)"

        }

    [pscustomobject] @{

        vCenter          = [System.Net.Dns]::GetHostEntry((Get-View $vmHost -ErrorAction SilentlyContinue).summary.managementserverip).HostName

        "ESXi Host Name" = $vmHost.Name

        Vendor           = $platform.VendorName

        Model            = $platform.ProductName

        Serial           = $platform.SerialNumber

        EOL              = $vmHostModelEolMapping[$platform.ProductName] -replace "^$", 'Unknown'

        }


} | Sort-Object vCenter, "ESXi Host Name" | Export-Excel @hash


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos