Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active March 31, 2024 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/84054b95a8f764b14c101350c228e159 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/84054b95a8f764b14c101350c228e159 to your computer and use it in GitHub Desktop.
Get the serial number and service tags for ESXi hosts
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
}
@AfroThundr3007730
Copy link
Author

Updated version available in my HelperFunctions module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment