VMware Cloud Community
Mallik7
Enthusiast
Enthusiast
Jump to solution

Need a PowerCLI script to get the "ESXi host name", "Host Hardware Vendor Name", "Host hardware model", "IP address", "Product full name"

Need a PowerCLI script to get the "ESXi host name", "Host Hardware Vendor Name", "Host hardware model", "IP address", "Product full name"

We have about 15 vCenters which I want to grab all the vCenter hosts information with one time. Thanks in advance.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case, just add the name

$global:DefaultVIServers | ForEach-Object {

   $vc = $_

   Get-VMHost -Server $vc |

  Select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel -Name vmk0).IP}},

   @{N='Product';E={$_.ExtensionData.Config.Product.FullName}}

  } | Export-Csv C:\Temp\report.csv -NoTypeInformation -UseCulture


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

View solution in original post

16 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

foreach($vc in $global:DefaultVIServers){

   Get-VMHost -Server $vc |

  Select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel).IP -join '|'}},

   @{N='Product';E={$_.extensionData.Client.ServiceContent.About.FullName}}

}


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

output I'm seeing vCenter production information, I need ESX hypervisor version, can you please correct it and also, please add below requirements -

how this can turned into a tabular format with .csv output - tabular format should be -->

HOST    HOST_VENDOR    HOST_MODEL    IP_ADDRESS    PRODUCT_FULLNAME (ESXi)

thank you

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$global:DefaultVIServers | ForEach-Object {

   Get-VMHost -Server $vc |

  Select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel).IP -join '|'}},

   @{N='Product';E={$_.ExtensionData.Config.Product.FullName}}

  } | Export-Csv C:\Temp\report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

for some reason, it is not capturing the vCenter information in the first tab. Could you please have a look.

and also, in the IP address tab, capturing 2 different IPs. I need only the IP address which is assigned to the host, not any thing else.

Previously, I used to receive emails when some one respond to my query. But, these days, I'm not receiving, not sure what is the reason....?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It seems I lost 1 line when I copied the snippet.

This should fix the vCenter issue.

On the IP addresses, those are the IP addresses assigned to the VMKernle adapters, if a node has more than 1 you will see more than one.

In such a case which IP address do you want to see? The one for vmk0?

There is an issue with emails being sent out for threads since more than 1 week.

Not sure how far the website admins are with fixing that.

$global:DefaultVIServers | ForEach-Object {

   $vc = $_

   Get-VMHost -Server $vc |

  Select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel).IP -join '|'}},

   @{N='Product';E={$_.ExtensionData.Config.Product.FullName}}

  } | Export-Csv C:\Temp\report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

thanks, it is capturing the vCenter info now. And yes, only the vmk0 is needed (management network IP address).

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case, just add the name

$global:DefaultVIServers | ForEach-Object {

   $vc = $_

   Get-VMHost -Server $vc |

  Select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel -Name vmk0).IP}},

   @{N='Product';E={$_.ExtensionData.Config.Product.FullName}}

  } | Export-Csv C:\Temp\report.csv -NoTypeInformation -UseCulture


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

Mallik7
Enthusiast
Enthusiast
Jump to solution

hello,

with this script, can you help to get the Cluster name as well. My requirement is, if I filter the vCenter name, should show the Cluster name along with what are the hosts which are there with that cluster.

TIA

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$global:DefaultVIServers | ForEach-Object {

   $vc = $_

   Get-VMHost -Server $vc |

   select @{N='vCenter';E={$vc.Name}},Name,

   @{N='Cluster';E={(Get-Cluster -VMHost $_).Name}},

   @{N='Vendor';E={$_.ExtensionData.Hardware.SystemInfo.Vendor}},

   @{N='Model';E={$_.ExtensionData.Hardware.SystemInfo.Model}},

   @{N='IP';E={(Get-VMHostNetworkAdapter -VMHost $_ -VMKernel -Name vmk0).IP}},

   @{N='Product';E={$_.ExtensionData.Config.Product.FullName}}

} | Export-Csv C:\Temp\report.csv -NoTypeInformation -UseCulture


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

vmk2014
Expert
Expert
Jump to solution

LucD,

Can we collect the same information at Cluster level and export to CSV ? I mean for each cluster in vSphere ?

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That last script includes the cluster, or do you mean something else?


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

vmk2014
Expert
Expert
Jump to solution

Thank you LucD.  I'm all set, that is what i was looking exactly. Let me try now

thanks

vmk

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

I tested it. Worked for me.

Thank you.

vmk

Reply
0 Kudos
Nileshbhandirge
Contributor
Contributor
Jump to solution

Thank you its work fine and can we add up time in it?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can add a calculated property

@{N='Uptime';E={
  "$([math]::round($_.ExtensionData.Summary.QuickStats.Uptime / 86400, 0)) days" 
}}


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

Reply
0 Kudos
CS026
Contributor
Contributor
Jump to solution

Thank you for sharing this! Very helpful.

I'd like to include a few other items and I haven't been able to figure out what I need.

Storage I/O control
DQLEN
NTP servers
DNS servers


Thanks again

Reply
0 Kudos