VMware Cloud Community
Sureshadmin
Contributor
Contributor
Jump to solution

Need a powershell script for collecting ESX host information

Hi,

I need a powershell script to collect the below given ESX host information from the Virtual Center. My environment VC:2.5, ESX hosts: 2.5, 3, 3.5

At present i have individual powershell one liner scripts for getting these details. Would be more useful to have a single script. Tried VESI, but not getting the report in the below given format.

ESX host name | Version | Build Number | Manufacturer | Model | Processor Type | Physical CPU count | Cores Count | Service Console IP | vMotion IP | HBA count | Physical NICS count

Thanks in advance!

Reply
0 Kudos
68 Replies
pmeqix
Contributor
Contributor
Jump to solution

hi Luc,

i combined most of the variants requested in this thread into a single file and appended Export-CSV at the end since I have more than 25 servers to get an inventory, however when running in PowerCLI 4.1.0U1 there were couple of obsolete parameters which I changed based on the info that was printed on the command line however now it doesn't get me the console IP and vmkernel IP..

Also is there a way to split the datastores and pnic's into multiple lines so that when Export-CSV works the resulting output is more readable than the way it currently has the enstries exported?

any help is highly appreciated.

I have attached the script so other's can also use it.

Note: I should have mentioned the new network adapter cmdlet is call Get-VMHostNetworkAdapter

http://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Get-VMHostNetworkAdapter.html

Message was edited by: pmeqix (to include the new network adapter cmdlet info)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

To get the console and vmkernel IP with the Get-VMHostNetworkAdapter cmdlet, change those 2 lines as follows.

@{N="Service Console IP";E={($_|Get-VMHostNetworkAdapter -Name vmk0).IP}},
@{N="vMotion IP";E={($_|Get-VMHostNetworkAdapter -Name vswif0).IP}},

To split the datastore and pnic info over multiple lines, would mean that you have to repeat all the other properties each time.

It would make the CSV much longer and more difficult to read imho.


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

Reply
0 Kudos
pmeqix
Contributor
Contributor
Jump to solution

LucD

Thanks for the prompt response and the update.

For anyone else who would like to use I have attached the updated script.

Note: This script currently does not still capture service console IP if your ESX host is running some old ESX 4.0 builds which do not use vmk0 for service console.

Message was edited by: pmeqix - To provide cavear on the shortcomings of the script

Reply
0 Kudos
arturka
Expert
Expert
Jump to solution

Hi

Brilliant work guys

Cheers

Artur

VCDX77 My blog - http://vmwaremine.com
Reply
0 Kudos
MithileshSudam1
Contributor
Contributor
Jump to solution

Hi Jeevenj,

Can you please also add CPU, Mem Utilisaiton, and ESX sensors data.

Thanks in advance

-Mithilesh

Reply
0 Kudos
Cheride
Contributor
Contributor
Jump to solution

Below script is all Good and I love it. But it is missing the Total memory configured on the ESX host. how can I get this using the same script.

ANy help in this regard will be appreciated.

Connect-VIServer <server> -User <user> -Password <password>
$HostReport = @()
Get-VMHost |Get-View |%{    
     $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, ip_address,vmotion_ip, HBA_num, P_nic
     $Report.Hostname = $_.Name
     $Report.version =$_.Config.Product.Version
     $Report.Build =$_.Config.Product.Build
     $Report.manufacture =$_.Hardware.SystemInfo.Vendor
     $Report.Model =$_.Hardware.SystemInfo.Model
     $Report.cpu_model =$_.Summary.Hardware.CpuModel
     $Report.core_num =$_.Hardware.CpuInfo.NumCpuCores
     if($Report.version -like "3.5.*"){
          $Report.ip_address =$_.Config.Network.ConsoleVnic.Spec.ip.ipaddress
     }
     else {$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}
     $Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress
     $Report.HBA_num =$_.Summary.Hardware.NumHBAs
     $Report.P_nic =$_.Config.Network.Pnic.count
     $HostReport += $Report
}
$HostReport | Export-Csv "C:\HostReport.csv" –NoTypeInformation

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this

Connect-VIServer <server> -User <user> -Password <password> 
$HostReport
= @() Get-VMHost |%{          $Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, core_num, totalmemoryMB, ip_address,vmotion_ip, HBA_num, P_nic
    
$Report.Hostname = $_.Name      $Report.version =$_.Version      $Report.Build =$_.Build      $Report.manufacture =$_.ExtensionData.Hardware.SystemInfo.Vendor      $Report.Model =$_.Model      $Report.cpu_model =$_.ExtensionData.Summary.Hardware.CpuModel      $Report.core_num =$_.ExtensionData.Hardware.CpuInfo.NumCpuCores      $Report.totalmemoryMB =$_.MemoryTotalMB      if($Report.version -like "3.5.*"){           $Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic.Spec.ip.ipaddress      }      else {$Report.ip_address =$_.ExtensionData.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}      $Report.vmotion_ip =$_.ExtensionData.Config.Vmotion.IpConfig.IpAddress
     $Report.HBA_num =$_.ExtensionData.Summary.Hardware.NumHBAs
    
$Report.P_nic =$_.ExtensionData.Config.Network.Pnic.count      $HostReport += $Report
} $HostReport | Export-Csv "C:\HostReport.csv" NoTypeInformation


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

Reply
0 Kudos
Cheride
Contributor
Contributor
Jump to solution

Thanks a lot and I really appreciate this. Hats Off to you for supporting people like us, even after many years with similar questions.

Is it possible to List the cluster name to the output file where each ESX host resides?

Since Get-Cluster and Get-vmhost are different, how do we do this?

Also, one last question,

How do you get ( learn or understand) the property value for each object? For example, $_.ExtensionData.Config.Network.Pnic.count

Reply
0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

Hi Luc

Is there a way that you can include the cluster name in this report?

Thanks

Reply
0 Kudos