Last active
March 31, 2024 18:55
-
-
Save AfroThundr3007730/84054b95a8f764b14c101350c228e159 to your computer and use it in GitHub Desktop.
Get the serial number and service tags for ESXi hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ESXiSerials { | |
<# | |
.SYNOPSIS | |
Get the serial number and service tags for ESXi hosts | |
#> | |
Param( | |
# Full name of host or a regex | |
[Parameter(Mandatory = $false)] | |
[string]$HostSpec | |
) | |
Get-View -ViewType HostSystem -Property Name, Hardware.SystemInfo ` | |
-Filter @{ 'Name' = $(if ($HostSpec) { $HostSpec } else { '' }) } | | |
Sort-Object -Property Name | Select-Object Name, | |
@{ | |
Name = 'Serials'; | |
Expression = { $_.Hardware.SystemInfo | Select-Object ` | |
@{ | |
Name = 'AssetTag'; | |
Expression = { $_.OtherIdentifyingInfo[0].IdentifierValue } | |
}, | |
@{ | |
Name = 'ServiceTag'; | |
Expression = { $_.OtherIdentifyingInfo[1].IdentifierValue } | |
}, | |
@{ | |
Name = 'EnclosureSerialNumberTag'; | |
Expression = { $_.OtherIdentifyingInfo[2].IdentifierValue } | |
}, | |
@{ | |
Name = 'SerialNumberTag'; | |
Expression = { $_.OtherIdentifyingInfo[3].IdentifierValue } | |
} | |
} | |
} | Select-Object Name -ExpandProperty Serials | Format-Table | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version available in my HelperFunctions module.