1 2 Previous Next 26 Replies Latest reply on Mar 3, 2020 5:06 AM by Ivan Ruotolo

    Unable get Serial Number of ESXi

    Ivan Ruotolo Novice
    vExpert

      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")

        • 1. Re: Unable get Serial Number of ESXi
          a.p. Guru
          Community WarriorsvExpertUser Moderators

          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

          • 3. Re: Unable get Serial Number of ESXi
            StephenMoll Hot Shot

            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.

            • 4. Re: Unable get Serial Number of ESXi
              LucD Guru
              Community WarriorsvExpertUser Moderators

              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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 5. Re: Unable get Serial Number of ESXi
                Ivan Ruotolo Novice
                vExpert

                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.

                 

                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.

                • 6. Re: Unable get Serial Number of ESXi
                  Ivan Ruotolo Novice
                  vExpert

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

                  • 7. Re: Unable get Serial Number of ESXi
                    LucD Guru
                    vExpertCommunity WarriorsUser Moderators

                    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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 8. Re: Unable get Serial Number of ESXi
                      LucD Guru
                      Community WarriorsvExpertUser Moderators

                      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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 9. Re: Unable get Serial Number of ESXi
                        Ivan Ruotolo Novice
                        vExpert

                        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

                         

                         

                        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.

                        • 10. Re: Unable get Serial Number of ESXi
                          LucD Guru
                          vExpertCommunity WarriorsUser Moderators

                          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 11. Re: Unable get Serial Number of ESXi
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 12. Re: Unable get Serial Number of ESXi
                              Ivan Ruotolo Novice
                              vExpert

                              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

                              • 13. Re: Unable get Serial Number of ESXi
                                LucD Guru
                                vExpertUser ModeratorsCommunity Warriors

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

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 14. Re: Unable get Serial Number of ESXi
                                  LucD Guru
                                  vExpertUser ModeratorsCommunity Warriors

                                  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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  1 2 Previous Next