How to export a list of ESXi hosts to a CSV file using PowerCLI

The Get-VMHost cmdlet returns a list of hosts with the below properties

Get-VMHost

Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz   MemoryUsageGB MemoryT
                                                                                                otalGB
----                 --------------- ---------- ------ ----------- -----------   ------------- -------
esxi1.example.com Connected       PoweredOn      12         201       28788          27.755 127.848
esxi2.example.com Connected       PoweredOn      12         211       28788           5.680 127.848
esxi3.example.com Connected       PoweredOn      12        3622       28788          50.854 127.848

To get specific properties

Get-VMHost  | Select-Object Name,Model, NumCpu, MemoryTotalGB

Name                      Model                                        NumCpu            MemoryTotalGB
----                      -----                                        ------            -------------
esxi1.example.com         UCSC-C240-M3S2                                   12        127.8477783203125
esxi2.example.com         UCSC-C240-M3S2                                   12        127.8477783203125
esxi3.example.com         UCSC-C240-M3S2                                   12        127.8477783203125

To see available properties

Get-VMHost | Get-Member

Export the output to a CSV file

Get-VMHost  | Select-Object Name,Model, NumCpu, MemoryTotalGB | Export-Csv -path  C:\HostInfo.csv -NoTypeInformation

Export this information to an HTML file

Get-VMHost  | Select-Object Name,Model, NumCpu, MemoryTotalGB | ConvertTo-Html | Set-Content  C:\HostInfo.html

For a specific cluster

Get-Cluster "$cluster" | Get-VMhost ...

For a specific datacenter

Get-Datacenter "$datacenter" | Get-VMhost ...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s