RTedrow
Contributor
Contributor

Getting Host Hardware Information through PowerCLI

Jump to solution

Hello there,

I have a list of information I would like to get from some of our hosts.  I've tried pulling this through PowerGUI and the VMWare PowerPacks but I'm having an issue with the fact that it will only pull down the hardware information for one of the hosts (even though I have 40 hosts connected under the managed hosts tab).

I obviously have a lot to learn in PowerCLI but I was hoping that someone could provide some direction on this.

I have a list of hosts that I have to connect with a pre-defined account and I'd like to pull down the following information into a CSV or some sort of report:

Hostname

Manufacturer / Model

Processor Type

Number of CPU / Cores

Speed of CPU

CPU Used

Total Memory

Memory Used

ESXi Version

All of the above information is avalible in PowerGUI but as I said I can only pull it for one host at a time for some reason.

If possible I'd love to be able to get a list of running VMs on each host at the same time.

I'd love some guidance on this or maybe if anyone has a bit more experience with PowerGUI and could let me know why it will only fill in the information for whatever my top listed host is.

I've found a few examples I think I could mash together but I con't figure out how to define a specific username/password and have it pull a list of hosts rather than one at a time.

It'd be awesome if someone had a similar script built and would let me take a look at it.

Thanks for any help you can lend.  I really appericiate this commnunity.  😃

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Once you get the hang of this, it becomes quite easy.

In your case, you want to list all your ESXi hosts and some properties for each host.

The basic idea is to use the Get-VMHost cmdlet.

Like this it will return all the ESXi servers in the vCenter to which you connected.

Get-VMHost

On screen you will see a number of default properties. This is determined by a kind of format file, but leave that for now.

The above cmdlet returns an object that has more properties. To see all the properties do a Get-Member

Get-VMHost | Get-Member

The next step is to select yourself which properties are to be displayed.

For that you use the Select-Object cmdlet, something like this

Get-VMHost | Select Name,Build,ConnectionState

If you want to store the result in a file, you can use for example the Export-Csv cmdlet.

Get-VMHost | Select Name,Build,ConnectionState | Export-Csv C:\report.csv -NoTypeInformation -UseCulture

If you want to learn about parameters that can be used on a cmdlet, you can use the Get-Help cmdlet.

For example

Get-Help Export-Csv -Parameter NoTypeInformation

will give help on that specific parameter. But you can also display the full help with

Get-Help Export-Csv -Full

That is in fact the basic concept behind reporting with PowerCLI/PowerShell;

  • get the objects
  • chose what you want to display
  • optionally save the result to a file

Does this get you on your way to start ?


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

View solution in original post

6 Replies
LucD
Leadership
Leadership

Once you get the hang of this, it becomes quite easy.

In your case, you want to list all your ESXi hosts and some properties for each host.

The basic idea is to use the Get-VMHost cmdlet.

Like this it will return all the ESXi servers in the vCenter to which you connected.

Get-VMHost

On screen you will see a number of default properties. This is determined by a kind of format file, but leave that for now.

The above cmdlet returns an object that has more properties. To see all the properties do a Get-Member

Get-VMHost | Get-Member

The next step is to select yourself which properties are to be displayed.

For that you use the Select-Object cmdlet, something like this

Get-VMHost | Select Name,Build,ConnectionState

If you want to store the result in a file, you can use for example the Export-Csv cmdlet.

Get-VMHost | Select Name,Build,ConnectionState | Export-Csv C:\report.csv -NoTypeInformation -UseCulture

If you want to learn about parameters that can be used on a cmdlet, you can use the Get-Help cmdlet.

For example

Get-Help Export-Csv -Parameter NoTypeInformation

will give help on that specific parameter. But you can also display the full help with

Get-Help Export-Csv -Full

That is in fact the basic concept behind reporting with PowerCLI/PowerShell;

  • get the objects
  • chose what you want to display
  • optionally save the result to a file

Does this get you on your way to start ?


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

RvdNieuwendijk
Leadership
Leadership

The following PowerCLI script retrieves the required information from all your hosts:

Get-VMHost |
Select-Object -Property Name,Manufacturer,Model,ProcessorType,
@{Name="NumCpuPackages";Expression={$_.ExtensionData.hardware.CpuInfo.NumCpuPackages}},
@{Name="NumCpuCores";Expression={$_.ExtensionData.hardware.CpuInfo.NumCpuCores}},
CpuTotalMhz,CpuUsageMhz,MemoryTotalGB,MemoryUsageGB,Version |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
RTedrow
Contributor
Contributor

LucD:  I really appericiate that.  That was far above what I was looking for.  You explained it very well and I've built the script I need off of your examples and explantion.  I will definitly be working with PowerCLI more - this is a great tool.

I was about to say you should write a book - but then I saw your sig. 😃  Thanks again for your quick primer and help with this project.  I'll almost definitly be picking up your book.

0 Kudos
RTedrow
Contributor
Contributor

Robert van den Nieuwendijk wrote:

The following PowerCLI script retrieves the required information from all your hosts:

Get-VMHost |
Select-Object -Property Name,Manufacturer,Model,ProcessorType,
@{Name="NumCpuPackages";Expression={$_.ExtensionData.hardware.CpuInfo.NumCpuPackages}},
@{Name="NumCpuCores";Expression={$_.ExtensionData.hardware.CpuInfo.NumCpuCores}},
CpuTotalMhz,CpuUsageMhz,MemoryTotalGB,MemoryUsageGB,Version |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture

Thanks for the example script Robert.  I'll be working with it tonight.  Really appericiate it!

0 Kudos
LucD
Leadership
Leadership

Thanks, glad it helped you.


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

0 Kudos
SandyD
Contributor
Contributor

Use RVtool to get details

0 Kudos