VMware Cloud Community
a2alpha
Expert
Expert
Jump to solution

summary.hardware - how to get esx host name not just the hardware spec

Hi,

I am currently running a script which outputs to a nice html document. One of the sections lists all the hardware info but doesn't have the esx server's name at the start, I am new to all this and still finding my feet so any help would be greatly appreciated.

Get-VMHost | Get-View | ForEach-Object { $_.Summary.Hardware } | Select-object Vendor, Model, MemorySize, CpuModel, CpuMhz, NumCpuPkgs, NumCpuCores, NumCpuThreads, NumNics, NumHBAs | ConvertTo-Html -title "VMware ESX server Hardware configuration" -body "<H4>VMware ESX server Hardware configuration.</H4>" | Out-File -Append $filelocation

Putting 'name' after the select-object just gives a blank column.

Thanks in advance.

Dan

0 Kudos
1 Solution

Accepted Solutions
tonygent
Enthusiast
Enthusiast
Jump to solution

Hi Dan,

Try this : (have also attached the code in case the site messes with it.

get-vmhost | % { get-view $_.ID } | Select-Object Name, @{ Name="Mem Size: "; Expression={$_.Summary.Hardware.memorySize}} , @{ Name="Vendor"; Expression={$_.Summary.Hardware.Vendor}} , @{ Name="Model"; Expression={$_.Summary.Hardware.Model}} , @{ Name="CPUModel"; Expression={$_.Summary.Hardware.CPUModel}}

This does not cover all the elements you did - but you should be able to add the rest. The reason your did not work was due to the "Name" property not being in the Summary.Hardware object. You need a method like this that references the .ID object for the Name property - the addresses the Summary.Hardware for the other elements you required.

Hope this helps - if so, please set as answered! - Been ages since I actually got there first :oD

TG

View solution in original post

0 Kudos
3 Replies
tonygent
Enthusiast
Enthusiast
Jump to solution

Hi Dan,

Try this : (have also attached the code in case the site messes with it.

get-vmhost | % { get-view $_.ID } | Select-Object Name, @{ Name="Mem Size: "; Expression={$_.Summary.Hardware.memorySize}} , @{ Name="Vendor"; Expression={$_.Summary.Hardware.Vendor}} , @{ Name="Model"; Expression={$_.Summary.Hardware.Model}} , @{ Name="CPUModel"; Expression={$_.Summary.Hardware.CPUModel}}

This does not cover all the elements you did - but you should be able to add the rest. The reason your did not work was due to the "Name" property not being in the Summary.Hardware object. You need a method like this that references the .ID object for the Name property - the addresses the Summary.Hardware for the other elements you required.

Hope this helps - if so, please set as answered! - Been ages since I actually got there first :oD

TG

0 Kudos
Zsoldier
Expert
Expert
Jump to solution

It's because the "Name" property doesn't exist under the $_.Summary.Hardware object.

Here is a better way to write it out:

$Report = @()

$ESXHosts = Get-VMHost | Get-View

ForEach ($ESXHost in $ESXHosts)

{

$ReportObj = "" | Select Name, Vendor, Model, MemorySize, CpuModel, CpuMhz, NumCpuPkgs, NumCpuCores, NumCpuThreads, NumNics, NumHBAs

$ReportObj.Name = $ESXHost.Name

$ReportObj.Vendor = $ESXHost.Summary.Hardware.Vendor

$ReportObj.Model = $ESXHost.Summary.Hardware.Model

$ReportObj.MemorySize = $ESXHost.Summary.Hardware.MemorySize

$ReportObj.CpuModel = $ESXHost.Summary.Hardware.CpuModel

$ReportObj.CpuMhz = $ESXHost.Summary.Hardware.CpuMhz

$ReportObj.NumCpuPkgs = $ESXHost.Summary.Hardware.NumCpuPkgs

$ReportObj.NumCpuCores = $ESXHost.Summary.Hardware.NumCpuCores

$ReportObj.NumCpuThreads = $ESXHost.Summary.Hardware.Threads

$ReportObj.NumNics = $ESXHost.Summary.Hardware.NumNics

$ReportObj.NumHBAs = $ESXHost.Summary.Hardware.NumHBAs

$Report += $ReportObj

}

$Report | ConvertTo-Html -title

"VMware ESX server Hardware configuration" -body "<H4>VMware ESX

server Hardware configuration.</H4>" | Out-File -encoding ASCII -Append

$filelocation

You should also encode as "ASCII" since leaving default seems to bloat the file and makes it render weird, especially when you add CSS styles. This also will allow the script to run faster since it grabs all the info on this line: "$ESXHosts = get-vmhosts | get-view". All the data available is now in $ESXHosts so you can add and delete information as you please. If you know info has not changed since the last time you ran the script, you can clear out the $Report variable and re-run from the 'ForEach' point to fill it up again with the information you are looking for.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
a2alpha
Expert
Expert
Jump to solution

Cheers guys, you have both been extremely helpful, really appreciate the speedy responses.

0 Kudos