vSphere Host Information Via PowerCLI

Recently I was required to gather some vSphere 4 host information for a documentation project. Some of this information is available and exportable from the vSphere 4 client but it's not all conveniently in the same place. I found it easier to gather this information via vSphere's PowerCLI rather than endlessly clicking around the interface.


get-vmhost | 
Select Name,
Manufacturer,
Model,
ConnectionState,
@{N="PhyMem"; E={[math]::truncate($_.MemoryTotalMB / 1024)} },
NumCpu,
@{N="Cores/CPU";E={$_.Extensiondata.Summary.Hardware.NumCpuCores/$_.Extensiondata.Summary.Hardware.NumCpuPkgs}},
@{N="Sockets";E={$_.Extensiondata.Summary.Hardware.NumCpuPkgs}}, 
@{N="Product";E={(Get-View $_.ID).Config.Product.FullName }} | 
Sort NameĀ | 
format-table -auto

The output looks something like this:


Name       Manufacturer              Model          ConnectionState PhyMem NumCpu Cores/CPU Sockets Product
----       ------------              -----          --------------- ------ ------ --------- ------- -------
x.x.x.x    Dell Inc.                 PowerEdge R710       Connected     47     12         6       2 VMware ESXi 4.1.0 build-123456
...

The output can easily be exported by replacing format-table with Export-Csv.