VMware Cloud Community
miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

Getting Serial Number Info from VMHost

Not long ago, I was introduced to a wonderful module known as "VI-Module".  It has given me access to some of the hardware data on a host that's quite elusive.  I was able to get the Manufacturer, Model, even BIOS and firmware dates.  However, what I'm trying to put together is a script which spits out the Serial Tag for any of these ESXi hosts (i.e. IBM Blades, etc).  I learned that "Bios" was a calculated field, but I haven't been able to figure out what it is derived from in order to pull that info.  I was expecting that if I could figure that out, then I could figure out how to substitute 'SerialTag' for BIOS.

I truly hope that someone can assist with this puzzle.  I have to provide a report which matches us the vCenters with their hosts by Serial Number. It's due COB Monday and my mind isn't working on full steam this afternoon.  Thanks in advance for your learned help.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you are using the V2 switch, this will show all properties returned

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


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

View solution in original post

14 Replies
zsoltesz
Enthusiast
Enthusiast
Jump to solution

I think, the surest method to use esxcli with PowerCLI.

$cli=Get-VMHost <hostname>|Get-EsxCli

Write-Host $cli.hardware.platform.get().SerialNumber

miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

I attempted to use zsoltesz's method; however it didn't work.  It's possible that since esxcli is now v2, there must be a different way to do it.  I tried using v2 since I'm running 6.5 R1, but even then I couldn't pull the information I needed.  I was certain that the answer would be somewhere in $esxcli.hardware.platform, but I wasn't able to pull "Service Tag" information.  A field for it has to be there since it's showing up in vCenter.  However, I don't have enough experience to know what parameter covers that field.  If I have to creating some type of 'calculated' field, then I'm really out of my depth.

Perhaps if I knew what parameters already exist in $esxcli.harware.platform.  I don't know how to write the line of script which would show all the options for that subset.  Does anyone know how to get that info?  I'm grasping at straws and I'm probably going in too many directions.  Any proper guidance that anyone can share would be greatly appreciated.  :smileycry:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you are using the V2 switch, this will show all properties returned

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


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

miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

Dude, as always, you are an undeniable Godsend.  I truly want to be like you when I grow up Smiley Happy.  I'm attempting now to write a script with that info, but have it be able to report on ALL hosts in a vCenter - some type of loop (i.e. a foreach statement) somewhere in the process.  I wish I had your brain.  It's  hard to get reacquainted once you've been out for a while.  Thanks for all the help.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

foreach($esxcli in Get-VMHost | Get-EsxCli -V2){

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

    Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber

}


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

miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

That's terrific LucD.  I was even able to refine it down to a specific parameter; now that I know what's available.  I'm tied up in an inventory for our Lenovo Maintenance Contracts.  We have a percentage of our hosts are IBM blades.  Everything else is Cisco UCS.  I was handed a sheet with Service Tags and told to tie those to whichever datacenter across the country it belongs to.  Then later, PowerCLI helped so much that I was asked to include the UCS tags as well.  Because of your help, I'm able to take a 3-4 hour task and change in over to perhaps 30-45 minutes.  If I tweak your loop formula just right, I may even be able to apply it in each our datacenters.  (We're busy doing the prep work to migrate to 6.0.0U2a.  Current environment has 4.1, 5,0, 5.1, and 5.5.  They wish to do the VMware environment first, then the NetApp environment, then the Cisco UCS stuff.  Nothing's been updated since it was originally installed so there's a lot of intermediate steps just getting everything onto one common build before taking them all to 6.   That's one of the reasons that they brought me on and I'm having the time of my life.  I get to do things now that I only dreamed about doing with VMware.  They're even letting me build a team sandbox!!!  No company that I've worked at over the past 15 years has ever let the engineers have their own R&D portal.  Things were always moving too fast and there were too few people.  Now the team is building ....

I just realized that I rambled again..sorry, I'm just so happy about your pointing me in the proper direction.  Just want to say thanks again; not just to you but also everyone else who has been trying to help.  I like to think that our collective expertise is growing exponentially.  Once you reach out to help someone, you advance them and yourself, a hundred-fold. 

Until next time...

Maraming salamat po (Many thanks, respectfully),

Miguel:smileycool:Smiley Happy

LucD
Leadership
Leadership
Jump to solution

You're welcome Smiley Happy


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

0 Kudos
miguelvelezwhit
Enthusiast
Enthusiast
Jump to solution

This worked as beautifully as the command.  I can't thank you enough.

I have one other related question:

Some of the IBM Blades that I'm looking for are NOT part of VMware.  I've been able to ping them, perform nslookup.  Heck I can even run NMAP on their network and get there FQDN names.  However, since it's not part of VMware, I won't be able to see it in PowerCLI; or anything else that's VMware related.  However, in an attempt to think out of the box, I thought that perhaps WMI had some equivalent parameters so that I could find this stuff via our new PowerShell.

Is that possible?  Or am I overreaching?

One last item:

I was attempting to go to your "powerclibook" which is listed under your profile info.  However, the site took me to a GoDaddy domain offering page.  Has that link changed?  If so, can you redirect me?

Thanks as always,
Miguel:smileyconfused:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, you're on the right track.
With WMI you should be able to query those blades.

Most of the time there are some prerequisites that need to be fulfilled before it works.

Unfortunately I don't have any IBM Blades to try it out right now.

Yes, that book link was invalid, seems that the website was abandoned.

I replaced the link in the footer, but there is also a link on my blog.


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

0 Kudos
FrankG203
Enthusiast
Enthusiast
Jump to solution

Hi LucD - 

Thank you for this, I have been using this script (edited a little to use in my environment), I am for some reason having an issue adding to it to grab the BIOS version and BIOS release date, which I use in a separate script, combining would be great, can you help me with this?  I am new to scripting 😕 I have tried adding foreach loops and/or custom objects to get the write out put and I am failing.

Get-View -ViewType HostSystem | Select Name,
@{N="BIOS version";E={$_.Hardware.BiosInfo.BiosVersion}},
@{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}}

Thanks in advance

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can try something like this

foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
    $esxcli.hardware.platform.get.Invoke() |
    Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber,
        @{N="BIOS version";E={$esxcli.VMHost.ExtensionData.Hardware.BiosInfo.BiosVersion}},
        @{N="BIOS date";E={$esxcli.VMHost.ExtensionData.Hardware.BiosInfo.releaseDate}}
}


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

FrankG203
Enthusiast
Enthusiast
Jump to solution

Thanks for the fast turnaround, so ridiculous I tried that exact thing and I had 0 output (I must of missed a comma or something UGH), any chance to configure output across instead of up/down so I can export to excel?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean that it is show in list format on the console?
That is due to the size and number of properties.
When you export it should be in CSV format.

$report = foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
    $esxcli.hardware.platform.get.Invoke() |
    Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber,
        @{N="BIOS version";E={$esxcli.VMHost.ExtensionData.Hardware.BiosInfo.BiosVersion},
        @{N="BIOS date";E={$esxcli.VMHost.ExtensionData.Hardware.BiosInfo.releaseDate}}
}
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

FrankG203
Enthusiast
Enthusiast
Jump to solution

Thank you LucD, you are a magician!

0 Kudos