Automation

 View Only

Generate ESXi Host EOL report 

Jan 31, 2020 11:15 AM

<#

        ===========================================

        Created By:   Jason Pierce

        Created on:   31/Jan/2020

        Version:         3.0 (Final)

        NOTE:           The $vCenters and $vmHostModelEolMapping variables need to be edited to include your environment details before running the script

        ===========================================

#>

# 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 -PipelineVariable vmhost -Process {

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

    $i++

    try {

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

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

        }

    catch {

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

        }

    [pscustomobject] @{

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

        "ESXi Host Name" = $_.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

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.