I've re-worked this to make it a bit more user friendly :smileygrin:
The script can take a long time to run, depending on quantity of VC's and Hosts so i've also added a progress bar.
If anyone thinks this can be optimized in any way, please feel free to post comments
# 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" = " "
"PowerEdge R710" = "2016/May"
# VxRails
"VxRail E460" = "2023/05"
"VxRail P570F"= " "
}
# Status Bar Variables
$vmHosts = Get-VMHost
$count = $vmHosts.count
$i = 1
# Collect Server details
$results = @()
foreach ($vmHost in $vmHosts) {
Write-Progress -Activity "Generating Server End Of Life Report" -Status "Getting info on $vmHost" -PercentComplete (($i*100)/$count)
$vcName = [System.Net.Dns]::GetHostEntry((Get-View $vmHost -ErrorAction SilentlyContinue).summary.managementserverip).HostName
$vmHostName = $vmHost.Name
$EolDate = "Unknown"
$vmHostVendor = ''
$vmHostModel = ''
$vmHostSerial = ''
try {
$esxcli = $null
$esxcli = Get-EsxCli -vmhost $vmHost -V2 -ErrorAction Stop
$vmHostVendor = $esxcli.hardware.platform.get.invoke().VendorName
$vmHostModel = $esxcli.hardware.platform.get.invoke().ProductName
$vmHostSerial = $esxcli.hardware.platform.get.invoke().SerialNumber
if ($vmHostModelEolMapping.ContainsKey($vmHostModel)) {
$EolDate = $vmHostModelEolMapping[$vmHostModel]
}
}
catch {
Write-Host -ForegroundColor red "Get-EsxCli failed for $($vmHost.Name)"
}
$prop = [pscustomobject] @{
vCenter = $vcName
"ESXi Host Name" = $vmHostName
Vendor = $vmHostVendor
Model = $vmHostModel
Serial = $vmHostSerial
EOL = $EolDate
}
$i++
$results += $prop
}
<#
requirement: ImportExcel module
Verify that ImportExcel is installed with 'Get-Module -ListAvailable ImportExcel'
If not installed, install with 'Find-Module ImportExcel | Install-Module'
Get available commands with 'Get-Command -Module ImportExcel'
#>
If (!(Get-module -ListAvailable "ImportExcel")) {
Find-Module -Name ImportExcel | Install-Module
}
$ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks
$hash = @{
Path = "C:\Temp\EOLreport.xlsx"
Show = $true;
AutoSize = $true;
AutoFilter = $true;
ConditionalText = $ContainsBlanks
ShowPercent = $true;
#PivotTableName = "ESXi Version Detail";
#IncludePivotTable = $true;
#PivotRows = 'Version';
#PivotData = @{'Version' = 'Count'};
#IncludePivotChart = $true;
#ChartType = "PieExploded";
HideSheet = "Sheet1";
}
Remove-Item $hash.Path -ErrorAction Ignore
$results | Sort-Object vCenter,"ESXi Host Name" | Export-Excel @hash