Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment