John John
John John

Reputation: 1

PowerShell script "Get-VMHost Hardware.SystemInfo.OtherIdentifyingInfo" will return 2 values for the service tag

I have the following power-shell script, where i want to get the ServiceTag for our servers:-

((Get-VMHost | Get-View).Hardware.SystemInfo.OtherIdentifyingInfo | ?{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue

But i have noted that for some servers I will get 2 values representing the service tag, so is this normal? if so then which one i can use to identify the server?

EDIT when i run this script:-

((Get-VMHost | Get-View).Hardware.SystemInfo.OtherIdentifyingInfo | ?{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue
foreach ($vmhost in Get-VMHost) {
    $ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo; $ServiceTag | Get-Member

    if ([string]::IsNullOrEmpty($ServiceTag)) { $ServiceTag = 'N/A' }

    Write-Host "$($vmhost.Name) - $ServiceTag"
}

I got this :-

Name            MemberType Definition
----            ---------- ----------
Equals          Method     bool Equals(System.Object obj)
GetHashCode     Method     int GetHashCode()
GetType         Method     type GetType()
ToString        Method     string ToString()
DynamicProperty Property   VMware.Vim.DynamicProperty[] DynamicProperty {get;set;}
DynamicType     Property   string DynamicType {get;set;}
IdentifierType  Property   VMware.Vim.ElementDescription IdentifierType {get;set;}
IdentifierValue Property   string IdentifierValue {get;set;}

Upvotes: 2

Views: 1631

Answers (1)

Theo
Theo

Reputation: 61243

This is actually a comment, but because it needs to be formatted in multiple lines I have added it as if an answer

What happens if you do

foreach ($vmhost in Get-VMHost) {
    $ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | 
                  Where-Object { $_.IdentifierType.Key -eq "ServiceTag"}

    if ([string]::IsNullOrEmpty($ServiceTag)) { $ServiceTag = 'N/A' }

    Write-Host "$($vmhost.Name) - $ServiceTag"
}

It appears the above does not return a string with the service tag, but an object. That object has a IdentifierValue property and that holds the string with the actual service tag. So we need to go one step deeper:

foreach ($vmhost in Get-VMHost) {
    $ServiceTag = $vmhost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | 
                  Where-Object { $_.IdentifierType.Key -eq "ServiceTag"}

    if (($ServiceTag) -and $ServiceTag.IdentifierValue) { 
        $ServiceTag = $ServiceTag.IdentifierValue
    }

    Write-Host "$($vmhost.Name) - $ServiceTag"
}

Edit

It seems when obtaining Serial Numbers from Physical Servers, you'll have to deal with the ways hardware vendors expose these attributes. Different vendors treat them differently.

The various code you already tried returns two values for IdentifierValue. This occurs because the hardware vendor, (like Cisco) presents serial numbers per Processor.

Found that here.

scroll down to the ESXi Physical Servers chapter

Upvotes: 2

Related Questions