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")
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
$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
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
Hi,
http://wintelspot.blogspot.com/2018/02/find-serial-number-of-vmware-esxi-host.html
ARomeo
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.
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
$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
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.
Thanks, I have about 4000 hosts which is why I need this information which I have already verified exists with a similar script.
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
$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
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
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.
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Did you try my latest version?
The one with the ExtensionData?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For completeness, the full script
$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
No, I try it now
At what point can insert the code ?
Get-VMHost | ForEach-Object -Process {
$ esxcli = Get-EsxCli -VMHost $ _ -V2
$ Esxcli.hardware.platform.get.Invoke ()
}
I added the full script as well
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I apologize but I can't find it.
This one
$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