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
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Then I'm at my wits end here.

It works for me and Robert also confirmed it worked for him.

Although I can't see why this would solve the problem, you could ultimately try an upgrade to PowerShell v2 RTM.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

Reply
0 Kudos
68 Replies
LucD
Leadership
Leadership
Jump to solution

Try this

Get-VMHost  | Select Name, Version,
	Build, Manufacturer, Model, ProcessorType,
	NumCPU, @{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
	@{N="Service Console IP";E={(($_|Get-VMHostNetwork).ConsoleNic | Select IP).IP}},
	@{N="vMotion IP";E={(($_|Get-VMHostNetwork).VirtualNic | Select IP).IP}},
	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}

For the Cores field I wasn't sure if you want the number of cores per processor block or the total number of cores on the server.

It now shows the cores per processor block.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
jeveenj
Enthusiast
Enthusiast
Jump to solution

Hi,

You can also try below code snippet.

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 
	$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

-If you found this information useful, please consider awarding points for Correct or Helpful.
Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

hi Lucd,

This script works perfectly on ESX 3.5.

But in ESX 2.5, 3 and 4 it doesn't give values for Service console IP, vMotion IP and HBA count.

Any ideas?

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

hi Jeevenj,

i get this error while running your script. Cannot index into a null array. At :line:12 char:51 + $Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress

Reply
0 Kudos
jeveenj
Enthusiast
Enthusiast
Jump to solution

Try this

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

Let me know if you find any empty parameter.

-If you found this information useful, please consider awarding points for Correct or Helpful.
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Works ok on ESX 4 for me.

For the HBA count I only select the FC HBAs, if you want to see other HBAs you can leave out the Where cmdlet on that line.

For the console and vkernel IP address there was a typo.

This should work for ESX 4

Get-VMHost <esx-name> | Select Name, Version,
	Build, Manufacturer, Model, ProcessorType,
	NumCPU, @{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}

Since there are square brackets involved and since the forum SW has problems with these, I attached the script.

Unfortunately I don't have an ESX 2.5 or 3 to test.

____________

Blog: LucD notes

Twitter: lucd22


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

RvdNieuwendijk
Leadership
Leadership
Jump to solution

I tested Luc's script on ESX 3.5 and it works ok.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

hi Lucd,

Can you please clarify how numCpu and cores count are calculated. I assume numCpu is physical processor count and cores count is cores per physical processor.

But in the report i see for many esx host the values for numCpu and Cores count are 8 and 8. Just confused, how is it calculated?

Also i have sent you a Private Message. Please check it.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The script gets the NumCPU value from the HostSystemImpl object that is returned by Get-VMHost.

This seems indeed to return the number of cores and not the number of physical processors.

Try this

Get-VMHost <esx-name> | Select Name, Version,
	Build, Manufacturer, Model, ProcessorType,
	@{N="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},
	@{N="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}},
	@{N="Service Console IP";E={($_|Get-VMHostNetwork).ConsoleNic[0].IP}},
	@{N="vMotion IP";E={($_|Get-VMHostNetwork).VirtualNic[0].IP}},
	@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},
	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}}

Now the NumCPU value is retrieved from the HostCpuInfo object.

____________

Blog: LucD notes

Twitter: lucd22


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

Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Now the script gives correct CPU and core values. So ESX 3.5 reporting is perfect now.

In ESX 4, now it displays values for vMotion IP and HBA count, but Service Console IP value is blank.

I have posted one more script requirement in http://communities.vmware.com/thread/262425 Please check whether do u have this script.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, it gives correct results in my environment.

Are you sure the square brackets are included?

Try the attached file.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

I checked whether square brackets are present. It's there.

I use VESI and also tried to execute from powercli console, but in both cases service console IP field is blank in ESX4.

I tried to attach the screenshots of the script and output, First time i got error "You are unauthorized to perform this operation, contact moderator" and message alone got posted without attachements. Tried second time but got a error "File is too large" for just 14Kb and 4kb gif files. i think forum software has a bug Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could you perhaps show the output of the following line ?

Get-VMHost <esx-hostname> | Get-VMHostNetwork | Select -ExpandProperty ConsoleNic

Run it from the PowerCLI prompt and paste in the result.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I used connect-viserver and connected to my ESX4 box. Then i ran the command given by you. But it gave no output. Just pasted it below.

C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Get-

VMHost | Get-VMHostNetwork | Select -ExpandProperty ConsoleNic

C:\Program Files\VMware\Infrastructure\vSphere PowerCLI>

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you running the latest PowerCLI build ?

Does

Get-PowerCLIVersion

return

PowerCLI Version
----------------
VMware vSphere PowerCLI 4.0 U1 build 208462

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

yes Luc,

I upgraded recently when i installed VESI and windows powershell version is 1

C:\> Get-PowerCLIVersion

PowerCLI Version

-


VMware vSphere PowerCLI 4.0 U1 build 208462

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then I'm at my wits end here.

It works for me and Robert also confirmed it worked for him.

Although I can't see why this would solve the problem, you could ultimately try an upgrade to PowerShell v2 RTM.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I can live with this script for now because my major requirement ESX3.5. I will upgrade powershell and give out a try once on ESX4. Thanks for this script, it has helped me a lot. Still i have 2 more script requirement will post it soon.

Given correct answer 10 points and helpful answers

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Need your help here. Can you please include the cluster name in the script. So the expected output looks like this.

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

If the ESX box does not belong to cluster this field can be blank.

Or, if you have a script to give out cluster wise esx host details, it is also ok for me.

Reply
0 Kudos