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
LucD
Leadership
Leadership
Jump to solution

Sure, try this

Get-VMHost | Select Name, Version,
	Build, 
	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
	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}}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Thank you so much Smiley Happy . If possible, whenever you have time please have a look at my storage script requirement.

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Posted a requirement for script to collect VM information. Please have a look http://communities.vmware.com/thread/264441

Reply
0 Kudos
TyLopes
Contributor
Contributor
Jump to solution

Using the info from LucD and jeveenj's posts, I mashed the following script to collect data from our multiple Vcenter instances, report includes info for socket and core count:

_________________________________________

$viservers = "vcenter1","vcenter2","vcenter3","vcenter4"

foreach ($singleViserver in $viservers)

{

Connect-VIServer $singleViserver

$HostReport = @()

Get-VMHost |Get-View |%{

$Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, cpu_num, 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.cpu_num =$_.Hardware.CpuInfo.NumCpuPackages

$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 ".\Full-HostReport.csv" –NoTypeInformation

_________________________________________

Thought someone else may look for this exact code since I was looking for it. As noted, it requires the latest version of PowerCli

Good work LucD and jeveenj!!

Ty Lopes

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Can you please give a script to list the below info from Virtual center,

VM name | ESX Name | Cluster name

If the vm is not part of the cluster please leave the value as blank.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try this

Get-VM | Select @{N="VM name";E={$_.Name}},
	@{N="ESX name";E={($_ | Get-VMHost).Name}},
	@{N="Cluster name";E={($_ | Get-Cluster).Name}}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Thank you so much.

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Need a help. Can you please add 2 more fields in this script

vSwitches ---> print names of all vswitch in the esx box seperated by commas.

Portgroups -


> print names of all portgroups in all switches seperated by commas.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Here you go.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Works perfect. Thanks a lot.

Reply
0 Kudos
necodemus
Contributor
Contributor
Jump to solution

Nice script, whould it be possible to add basic Iscsi information like ip address for each HBA adaptor ? It would also be nice to send the result to a csv. or word document.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you mean the IP address of the IScsi targets ?

Like this ?

Get-VMHost | Get-View | %{
	$esx = $_
	$esx.Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{
		$hba = $_
		$_.ConfiguredSendTarget | `
			Select @{N="ESX Name";E={$esx.Name}},
			@{N="HBA Device";E={$hba.Device}},
			@{N="IScsi Name";E={$hba.IScsiName}},
			@{N="IScsi Target";E={$_.Address}}
	}
} | Export-Csv "C:\IScsi.csv" -NoTypeInformation -UseCulture

To store this result on a worksheet in a XLS file have a look at my Beyond Export-Csv: Export-Xls post.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
necodemus
Contributor
Contributor
Jump to solution

no, I mean the ip address of the Iscsi Adaptor in the ESX server.

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Can you please add 2 more fields to this script,

Datastores ---> The name of all datastores that ESX can see separated by commas.

WWN ---> The WWN of all HBA cards seperated by commas.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Here you go.

Note that I added a 3th field, called "FC Devices", that will allow you see which "FC WWN" belongs to which HBA.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Thank you so much.

Can you please change the output of the datastore field to show capacity as well like given below.

DatastoreName(CapacityInGB)

Example: vmfs12(200), vmfs13(250)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Yes, working fine. Thank you so much, Luc.

Reply
0 Kudos
necodemus
Contributor
Contributor
Jump to solution

Luc, this is what I was looking for but since I don't know how to program I don't know how to add the ip target to the result.

VMHost | Get-View | %{

$esx = $_

$esx.Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{

$hba = $_

$_.ipProperties |`

Select @{N="ESX Name";E={$esx.Name}},

@{N="HBA Device";E={$hba.Device}},

@{N="IScsi IP";E={$_.Address}}

}

$_.ConfiguredSendTarget |`

Select @{N="IScsi IP";E={$_.Address}}

} | Out-GridView

when it comes to programming, the best I can do is change lines or adding stuff coming from others script, but I don't really know what I do.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can get those line in the script like this

Get-VMHost | Select Name, Version,
	Build, 
	@{N="Cluster Name";E={($_ | Get-Cluster).Name}},
	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="DatastoreName(Capacity in GB)";E={[string]::Join(",",( $_ | Get-Datastore | %{$_.Name + "(" + ("{0:f1}" -f ($_.CapacityMB/1KB)) + ")"}))}},
	@{N="FC Device";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{$_.Device}))}},
	@{N="FC WWN";E={[string]::Join(",",(($_ | Get-View).Config.StorageDevice.HostBusAdapter | where{$_.GetType().Name -eq "HostFibreChannelHba"} | %{"{0:x}" -f $_.NodeWorldWideName}))}},
	@{N="Physical NICS count";E={($_ | Get-View).Config.Network.Pnic.Count}},
	@{N="vSwitches";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name}))}},
	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
	@{N="IScsi HBA Name";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.Device}))}},
	@{N="IScsi IP addr";E={[string]::Join(",",(($_| Get-View).Config.StorageDevice.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | %{$_.ipProperties.address}))}}

But I think the IP address won't be in the property when it concerns a "soft" IScsi setup.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos