Skip to content

Commit e86c0fb

Browse files
author
William Lam
committed
Inventory standalone ESXi host core countn for vSphere+/vSAN+
1 parent 5d3be98 commit e86c0fb

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<#PSScriptInfo
2+
.VERSION 1.0.0
3+
.GUID d893723e-86a9-4483-91e4-75f7a8a23b27
4+
.AUTHOR William Lam
5+
.COMPANYNAME VMware
6+
.COPYRIGHT Copyright 2023, William Lam
7+
.TAGS VMware
8+
.LICENSEURI
9+
.PROJECTURI https://github.com/lamw/vmware-scripts/blob/master/powershell/StandaloneHostvSpherePlusCPUSocketToCoreUsage.ps1
10+
.ICONURI https://blogs.vmware.com/virtualblocks/files/2018/10/PowerCLI.png
11+
.EXTERNALMODULEDEPENDENCIES
12+
.REQUIREDSCRIPTS
13+
.EXTERNALSCRIPTDEPENDENCIES
14+
.RELEASENOTES
15+
1.0.0 - Initial Release
16+
.PRIVATEDATA
17+
.DESCRIPTION This function retrieves vSphere+/vSAN+ CPU Core Usage Analysis for Standalone ESXi hosts (unmanaged)
18+
#>
19+
20+
Function Get-StandalonevSpherePlusCPUSocketToCoreUsage {
21+
<#
22+
.DESCRIPTION Retrieves vSphere+/vSAN+ CPU Core Usage Analysis for Standalone ESXi hosts (unmanaged)
23+
.NOTES Author: William Lam, VMware
24+
.PARAMETER InputFile
25+
Input text file containing list of standalone ESXi hosts delimited by hostname/ip,username,password.
26+
You can also comment out an entry if it starts with # symbol
27+
.PARAMETER Filename
28+
Specific filename to save CSV file (default: standalone-esxi-report-<date>.csv)
29+
.EXAMPLE
30+
Get-StandalonevSpherePlusCPUSocketToCoreUsage
31+
.EXAMPLE
32+
Get-StandalonevSpherePlusCPUSocketToCoreUsage -InputFile host.txt
33+
.EXAMPLE
34+
Get-StandalonevSpherePlusCPUSocketToCoreUsage -InputFile host.txt -CSV
35+
.EXAMPLE
36+
Get-StandalonevSpherePlusCPUSocketToCoreUsage -CSV -Filename myhosts.csv
37+
#>
38+
param(
39+
[Parameter(Mandatory=$false)][string]$InputFile,
40+
[Parameter(Mandatory=$false)][string]$Filename,
41+
[Switch]$Csv
42+
)
43+
44+
# Helper Function to build out CPU usage object
45+
Function BuildvSpherePlusCPUSocketToCoreUsage {
46+
param(
47+
[Parameter(Mandatory=$true)]$vmhost
48+
)
49+
50+
$vmhostName = $vmhost.name
51+
52+
$sockets = $vmhost.Hardware.CpuInfo.NumCpuPackages
53+
$coresPerSocket = ($vmhost.Hardware.CpuInfo.NumCpuCores / $sockets)
54+
55+
# Check if hosts is running vSAN
56+
if($vmhost.Runtime.VsanRuntimeInfo.MembershipList -ne $null) {
57+
$isVSANHost = $true
58+
} else {
59+
$isVSANHost = $false
60+
$vsanPlusLicenseCount = 0
61+
}
62+
63+
# vSphere+ & vSAN+
64+
if($coresPerSocket -le 16) {
65+
$vspherePlusLicenseCount = $sockets * 16
66+
if($isVSANHost) {
67+
$vsanPlusLicenseCount = $sockets * 16
68+
}
69+
} else {
70+
$vspherePlusLicenseCount = $sockets * $coresPerSocket
71+
if($isVSANHost) {
72+
$vsanPlusLicenseCount = $sockets * $coresPerSocket
73+
}
74+
}
75+
76+
$tmp = [pscustomobject] @{
77+
VMHOST = $vmhostName;
78+
NUM_CPU_SOCKETS = $sockets;
79+
NUM_CPU_CORES_PER_SOCKET = $coresPerSocket;
80+
VSPHEREPLUS_LICENSE_CORE_COUNT = $vspherePlusLicenseCount;
81+
VSANPLUS_LICENSE_CORE_COUNT = $vsanPlusLicenseCount
82+
}
83+
84+
return $tmp
85+
}
86+
87+
$results = @()
88+
foreach ($line in [System.IO.File]::ReadLines($InputFile)) {
89+
if($line -notmatch "^#") {
90+
$esxi_host,$esxi_username,$esxi_password = $line.split(",")
91+
92+
Write-Host "Querying ${esxi_host} ..." -ForegroundColor Green
93+
94+
$viConnection = Connect-VIServer -Server ${esxi_host} -User ${esxi_username} -Password ${esxi_password}
95+
96+
$vmhost = Get-View -Server $viConnection -ViewType HostSystem -Property Name,Hardware.systemInfo,Hardware.CpuInfo,Runtime
97+
if($vmhost.Hardware.systemInfo.Model -ne "VMware Mobility Platform") {
98+
$result = BuildvSpherePlusCPUSocketToCoreUsage -vmhost $vmhost
99+
100+
$results += $result
101+
}
102+
Disconnect-VIServer $viConnection -Confirm:$false
103+
}
104+
}
105+
106+
if($CSV) {
107+
If(-Not $Filename) {
108+
$Filename = "standalone-esxi-report-$(Get-Date -Format 'MMddyyyTHHmmss').csv"
109+
}
110+
111+
Write-Host "`nSaving output as CSV file to $Filename`n"
112+
$results | ConvertTo-Csv -NoTypeInformation | Out-File -FilePath $Filename
113+
} else {
114+
if (($results | measure).Count -eq 0) {
115+
Write-Host "`nHosts were not found with searching criteria`n" -ForegroundColor Red
116+
} else {
117+
$results | ft
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)