VMware Cloud Community
ivanunnio
Enthusiast
Enthusiast
Jump to solution

Unable get Serial Number of ESXi

Hi, kindness, help on the line to retrieve the server serial number.

In practice, when I run the script I recover all the information except the serial number of the server.

This is the row (@{N="Serial Number";  Expression = { ($_.Hardware.SystemInfo.OtherIdentifyingInfo | where { $_.IdentifierType.Key -eq "ServiceTag" }).IdentifierValue } },)

Where am I going wrong?

Thanks so much

# Inserire il Virtual Center desiderato

$hosts = "xxxxxxxxx"

# Inserire le credenziali del Virtual Center

$user = "xxxx"

$password = "xxxxxxxx"

# Mi collego al VC

Connect-VIServer $hosts  -User $user -Password $password #-SaveCredentials

# Definisco la variabile globale

$VMHosts = Get-VMHost

#$VMHosts = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

$Inventory = ForEach ($VMHost in $VMHosts)

   {

   "" | Select-Object -Property @{N="Name";E={$VMHost.Name}},

   @{N="Vendor";E={(Get-View -ViewType HostSystem -Filter @{"Name" = $VMHost.Name}).Hardware.Systeminfo.Vendor}},

   @{N="Model";E={(Get-View -ViewType HostSystem -Filter @{"Name" = $VMHost.Name}).Hardware.Systeminfo.Model}},

   @{N="Serial Number";  Expression = { ($_.Hardware.SystemInfo.OtherIdentifyingInfo | where { $_.IdentifierType.Key -eq "ServiceTag" }).IdentifierValue } },

   @{N="CPU Model";E={$VMHost.ExtensionData.Summary.Hardware.CpuModel}},

   @{N="Datacenter";E={(Get-Datacenter -VMHost $VMHost.Name).Name}},

   @{N="Cluster";E={(Get-Cluster -VMHost $VMHost.Name).Name}},

   @{N="Hypervisor";E={$VMHost.Extensiondata.Config.Product.Name}},

   @{N="Hypervisor Version";E={$VMHost.Extensiondata.Config.Product.Version}},

   @{N="Clock Speed (Mhz)";E={$VMHost.ExtensionData.Summary.Hardware.CpuMhz}},

   @{N="Memory (MB)";E={$VMHost.MemoryTotalMB}},

   @{N="Hyperthreading Enabled";E={$VMHost.HyperThreadingActive}},

   @{N="Number of Cores";E={$VMHost.ExtensionData.Summary.Hardware.numCpuCores}}

   }

  

$Inventory | Write-Output

# $Inventory | Export-Csv -NoTypeInformation -Path ("C:\scripts\repository\sal\Inv_hosts_600xBO.csv")

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If the serialnumber is available, which is not always the case, the easiest way is to use the Get-VMHostHardware cmdlet.

PS: I also made some other changes to your script

# Inserire il Virtual Center desiderato

$hosts = "xxxxxxxxx"


# Inserire le credenziali del Virtual Center

$user = "xxxx"

$password = "xxxxxxxx"


# Mi collego al VC

Connect-VIServer $hosts  -User $user -Password $password #-SaveCredentials


# Definisco la variabile globale

$VMHosts = Get-VMHost

#$VMHosts = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

$Inventory = ForEach ($VMHost in $VMHosts)

   {

   "" | Select-Object -Property @{N="Name";E={$VMHost.Name}},

   @{N="Vendor";E={$VMHost.ExtensionData.Hardware.Systeminfo.Vendor}},

   @{N="Model";E={$VMHost.ExtensionData.Hardware.Systeminfo.Model}},

   @{N="Serial Number";  Expression = { (Get-VMHostHardware -VMHost $VMHost).SerialNumber },

   @{N="CPU Model";E={$VMHost.ExtensionData.Summary.Hardware.CpuModel}},

   @{N="Datacenter";E={(Get-Datacenter -VMHost $VMHost).Name}},

   @{N="Cluster";E={(Get-Cluster -VMHost $VMHost).Name}},

   @{N="Hypervisor";E={$VMHost.Extensiondata.Config.Product.Name}},

   @{N="Hypervisor Version";E={$VMHost.Extensiondata.Config.Product.Version}},

   @{N="Clock Speed (Mhz)";E={$VMHost.ExtensionData.Summary.Hardware.CpuMhz}},

   @{N="Memory (MB)";E={$VMHost.MemoryTotalMB}},

   @{N="Hyperthreading Enabled";E={$VMHost.HyperThreadingActive}},

   @{N="Number of Cores";E={$VMHost.ExtensionData.Summary.Hardware.numCpuCores}}

   }


$Inventory | Write-Output


# $Inventory | Export-Csv -NoTypeInformation -Path ("C:\scripts\repository\sal\Inv_hosts_600xBO.csv")


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
26 Replies
a_p_
Leadership
Leadership
Jump to solution

Please take a look at Solved: Getting hardware product ID & Serial number​ to see whether the information there helps you to find the wanted information.

André

PS: Discussion moved from ESXi to VMware PowerCLI

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

I have found that field rarely useful.

I have around 50 hosts that are regularly fingerprinted using RVTools. Not all will return a value for Serial Number and this is with all hosts from the same vendor (Dell). Some hosts have been factory reset at some point to resolve a problem, and it would appear this can remove any vendor information from the BIOS, including serial number.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If the serialnumber is available, which is not always the case, the easiest way is to use the Get-VMHostHardware cmdlet.

PS: I also made some other changes to your script

# Inserire il Virtual Center desiderato

$hosts = "xxxxxxxxx"


# Inserire le credenziali del Virtual Center

$user = "xxxx"

$password = "xxxxxxxx"


# Mi collego al VC

Connect-VIServer $hosts  -User $user -Password $password #-SaveCredentials


# Definisco la variabile globale

$VMHosts = Get-VMHost

#$VMHosts = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

$Inventory = ForEach ($VMHost in $VMHosts)

   {

   "" | Select-Object -Property @{N="Name";E={$VMHost.Name}},

   @{N="Vendor";E={$VMHost.ExtensionData.Hardware.Systeminfo.Vendor}},

   @{N="Model";E={$VMHost.ExtensionData.Hardware.Systeminfo.Model}},

   @{N="Serial Number";  Expression = { (Get-VMHostHardware -VMHost $VMHost).SerialNumber },

   @{N="CPU Model";E={$VMHost.ExtensionData.Summary.Hardware.CpuModel}},

   @{N="Datacenter";E={(Get-Datacenter -VMHost $VMHost).Name}},

   @{N="Cluster";E={(Get-Cluster -VMHost $VMHost).Name}},

   @{N="Hypervisor";E={$VMHost.Extensiondata.Config.Product.Name}},

   @{N="Hypervisor Version";E={$VMHost.Extensiondata.Config.Product.Version}},

   @{N="Clock Speed (Mhz)";E={$VMHost.ExtensionData.Summary.Hardware.CpuMhz}},

   @{N="Memory (MB)";E={$VMHost.MemoryTotalMB}},

   @{N="Hyperthreading Enabled";E={$VMHost.HyperThreadingActive}},

   @{N="Number of Cores";E={$VMHost.ExtensionData.Summary.Hardware.numCpuCores}}

   }


$Inventory | Write-Output


# $Inventory | Export-Csv -NoTypeInformation -Path ("C:\scripts\repository\sal\Inv_hosts_600xBO.csv")


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

Good morning and thanks LucD you're always the most professional is prepared.

I wanted to inform you that I applied your changes but as you can see it doesn't seem to work.

pastedImage_7.png

I used a simple script that I show you for an example and the serial number information is retrieved.

Connect-VIServer -Server  "txxxxxxxxx" -User "root" -Password "xxxxxxxx"

$hostname = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

foreach ($hname in $hostname)

{

$hn = $hname.name

$Man = $hname.Hardware.SystemInfo.Vendor

$Mod = $hname.Hardware.SystemInfo.Model

$serviceTag = $($hname.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue

$hname | Add-Member -MemberType NoteProperty -Name VMHost -Value $hn

$hname | Add-Member -MemberType NoteProperty -Name OEM -Value $Man

$hname | Add-Member -MemberType NoteProperty -Name Model -Value $Mod

$hname | Add-Member -MemberType NoteProperty -Name ServiceTag -Value $serviceTag

}

$hostname | select VMHost, OEM, Model, ServiceTag

There is something that escapes me.

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

Thanks, I have about 4000 hosts which is why I need this information which I have already verified exists with a similar script.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

So your original line does find the serial number with?


$serviceTag = $($hname.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue

When you do

Get-VMHost | Get-VMHostHardware | Format-List

does the number appear?

An alternative is to try the following

Get-VMHost | ForEach-Object -Process {

    $esxcli = Get-EsxCli -VMHost $_ -V2

    $esxcli.hardware.platform.get.Invoke()

}

This HW specific information is very much depending on how the HW vendor implemented it.

VMware expects this info to be available in a specific field/location.

If it is not in there, but in another field, the Get-VMHostHardware will not find it.

And you are forced to use the OtherIdentifyingInfo field, which doesn't work for all HW either.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are all the servers HP Proliant servers?

If you have iLO on these servers, it might be worth looking at using the HPEiLOCmdlets module.
That should work, see for example Help getting the SerialNumber using PowerShell


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

Hello,

Let me explain better, I used a small script to understand if the information I was interested in existed.

This is the result:

Connect-VIServer -Server  "XXXXXXX" -User "root" -Password "XXXXX"

$hostname = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

foreach ($hname in $hostname)

{

$hn = $hname.name

$Man = $hname.Hardware.SystemInfo.Vendor

$Mod = $hname.Hardware.SystemInfo.Model

$serviceTag = $($hname.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue

$hname | Add-Member -MemberType NoteProperty -Name VMHost -Value $hn

$hname | Add-Member -MemberType NoteProperty -Name OEM -Value $Man

$hname | Add-Member -MemberType NoteProperty -Name Model -Value $Mod

$hname | Add-Member -MemberType NoteProperty -Name ServiceTag -Value $serviceTag

}

$hostname | select VMHost, OEM, Model, ServiceTag

pastedImage_6.png

In this way I understood that the serial number was positioned in the right place.

At this point I started working on my script but in that case I can't recover the serial number.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

So the serial number is under the ServiceTag in the OtherIdentifyingInfo property.
I'm confused. What is the problem then?

Your script seems to work I understand.
Or do you want to get it working in another script?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I think I understand what happens.

You commented out the Get-View line, so the line for the Serial Number should be going via the ExtensionData property.

Like this

@{N="Serial Number";  Expression = {($VMHost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue}},


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

That's right, in my script the serial number doesn't work, while in the script I used for testing it works.

Because ?

This is the Test Script :

Connect-VIServer -Server  "xxxxxx" -User "root" -Password "xxxxx"

$hostname = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

foreach ($hname in $hostname)

{

$serviceTag = $($hname.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue

$hname | Add-Member -MemberType NoteProperty -Name ServiceTag -Value $serviceTag

}

$hostname | select   ServiceTag

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try my latest version?
The one with the ExtensionData?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

For completeness, the full script

# Inserire il Virtual Center desiderato

$hosts = "xxxxxxxxx"


# Inserire le credenziali del Virtual Center

$user = "xxxx"

$password = "xxxxxxxx"


# Mi collego al VC

Connect-VIServer $hosts  -User $user -Password $password #-SaveCredentials


# Definisco la variabile globale

$VMHosts = Get-VMHost

#$VMHosts = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

$Inventory = ForEach ($VMHost in $VMHosts)

   {

   "" | Select-Object -Property @{N="Name";E={$VMHost.Name}},

   @{N="Vendor";E={$VMHost.ExtensionData.Hardware.Systeminfo.Vendor}},

   @{N="Model";E={$VMHost.ExtensionData.Hardware.Systeminfo.Model}},

   @{N="Serial Number";  Expression = {($VMHost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue}},

   @{N="CPU Model";E={$VMHost.ExtensionData.Summary.Hardware.CpuModel}},

   @{N="Datacenter";E={(Get-Datacenter -VMHost $VMHost).Name}},

   @{N="Cluster";E={(Get-Cluster -VMHost $VMHost).Name}},

   @{N="Hypervisor";E={$VMHost.Extensiondata.Config.Product.Name}},

   @{N="Hypervisor Version";E={$VMHost.Extensiondata.Config.Product.Version}},

   @{N="Clock Speed (Mhz)";E={$VMHost.ExtensionData.Summary.Hardware.CpuMhz}},

   @{N="Memory (MB)";E={$VMHost.MemoryTotalMB}},

   @{N="Hyperthreading Enabled";E={$VMHost.HyperThreadingActive}},

   @{N="Number of Cores";E={$VMHost.ExtensionData.Summary.Hardware.numCpuCores}}

   }


$Inventory | Write-Output


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

No, I try it now

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

At what point can insert the code ?

Get-VMHost | ForEach-Object -Process {

     $ esxcli = Get-EsxCli -VMHost $ _ -V2

     $ Esxcli.hardware.platform.get.Invoke ()

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I added the full script as well


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ivanunnio
Enthusiast
Enthusiast
Jump to solution

I apologize but I can't find it.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This one

# Inserire il Virtual Center desiderato

$hosts = "xxxxxxxxx"


# Inserire le credenziali del Virtual Center

$user = "xxxx"

$password = "xxxxxxxx"


# Mi collego al VC

Connect-VIServer $hosts  -User $user -Password $password #-SaveCredentials


# Definisco la variabile globale

$VMHosts = Get-VMHost

#$VMHosts = Get-View -ViewType HostSystem -property name,Hardware.SystemInfo

$Inventory = ForEach ($VMHost in $VMHosts)

   {

   "" | Select-Object -Property @{N="Name";E={$VMHost.Name}},

   @{N="Vendor";E={$VMHost.ExtensionData.Hardware.Systeminfo.Vendor}},

   @{N="Model";E={$VMHost.ExtensionData.Hardware.Systeminfo.Model}},

   @{N="Serial Number";  Expression = {($VMHost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “ServiceTag” }).IdentifierValue}},

   @{N="CPU Model";E={$VMHost.ExtensionData.Summary.Hardware.CpuModel}},

   @{N="Datacenter";E={(Get-Datacenter -VMHost $VMHost).Name}},

   @{N="Cluster";E={(Get-Cluster -VMHost $VMHost).Name}},

   @{N="Hypervisor";E={$VMHost.Extensiondata.Config.Product.Name}},

   @{N="Hypervisor Version";E={$VMHost.Extensiondata.Config.Product.Version}},

   @{N="Clock Speed (Mhz)";E={$VMHost.ExtensionData.Summary.Hardware.CpuMhz}},

   @{N="Memory (MB)";E={$VMHost.MemoryTotalMB}},

   @{N="Hyperthreading Enabled";E={$VMHost.HyperThreadingActive}},

   @{N="Number of Cores";E={$VMHost.ExtensionData.Summary.Hardware.numCpuCores}}

   }


$Inventory | Write-Output


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos