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
necodemus
Contributor
Contributor
Jump to solution

Great it's working. I don't really care about soft iniator since we are not using it. I have been trying to make this work by myself for the past 4 hours. I was not so far from what you post. Thank you very much this will be very helpfull.

Question: adding Out-GridView or Export-Csv and the end of the script would probably not work ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can add Export-Csv or Out-GridView without a problem.

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}))}} | `
Out-GridView

You pipe the output of the Select-Object cmdlet to the Out-GridView or Export-Csv cmdlet.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
necodemus
Contributor
Contributor
Jump to solution

Great it's working, I tried it before but it didn't worked. I must have made a mistake somewhere.

Thanks again.

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

hi Luc,

Can you please alter the output of vSwitch field like vSwitchName(no. of ports)

Eg. vSwitch1(56)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There you go.

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(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Can you please add 2 fields to this script as given below,

pNIC MAC --> Mac address of the Physical Nics in the ESX box seperated by commas.

SC Mem --> Service console memory allocated to the ESX host

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There you go

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(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
	@{N="pNIC MAC";E={[string]::Join(",",($_ | Get-VMHostNetworkAdapter | %{$_.MAC}))}},
	@{N="SC Mem (MB)";E={"{0:f1}" -f (($_| Get-View).Config.ConsoleReservation.ServiceConsoleReserved/1MB)}}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
pranab2818
Enthusiast
Enthusiast
Jump to solution

Luc,

Can you please add 2 fields to this script as given below,

vKernel Vlan ID :

Service Console Vlan ID:

Thanks

Reply
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Thanks Luc.

I also added the ESX UUID to the script with the below line of code

@{N="UUID";E={($_| Get-View).summary.hardware.uuid}}

Reply
0 Kudos
pranab2818
Enthusiast
Enthusiast
Jump to solution

Hi,

Can anyone help me out in finding Vlan ID of Service Console & VMkernel.

Thanks in Advance :smileyblush:

Pranab

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To find the Vlan ID of the Service Console and VMkernel of all hosts you can use the next script:

Get-VMHost | Sort-Object -property Name | `
  ForEach-Object {
    $VMHost = $_
      $VMHost | Get-VirtualPortGroup | `
        Select-Object -Property @{N="VMHost";E={$VMHost.Name}},@{N="VirtualPortGroup";E={$_.Name}},VlanId | `
        Where-Object {$_.VirtualPortGroup -eq "Service Console" -or $_.VirtualPortGroup -eq "VMkernel"}
  }

Regards, Robert

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

Hey Robert Thanks for the script, Can we integrate this script with LUCs script? My requirement is one script.

Pranab

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Pranab,

here you get Luc's and my script integrated:

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(Number of Ports)";E={[string]::Join(",",( $_ | Get-VirtualSwitch | %{$_.Name + "(" + $_.NumPorts + ")"}))}},
	@{N="Portgroups";E={[string]::Join(",",( $_ | Get-VirtualPortGroup | %{$_.Name}))}},
	@{N="pNIC MAC";E={[string]::Join(",",($_ | Get-VMHostNetworkAdapter | %{$_.MAC}))}},
	@{N="SC Mem (MB)";E={"{0:f1}" -f (($_| Get-View).Config.ConsoleReservation.ServiceConsoleReserved/1MB)}},
	@{N="SC VlanId";E={($_| Get-VirtualPortGroup | Where-Object {$_.Name -eq "Service Console"}).VlanId}},
	@{N="VMKernel VlanId";E={($_| Get-VirtualPortGroup | Where-Object {$_.Name -eq "VMkernel"}).VlanId}}

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

Hi Robert,

Thanks for help, Really Appreciate it.

Pranab

Reply
0 Kudos
mldmld
Enthusiast
Enthusiast
Jump to solution

Hi all,How the get - the serial num of the hardware ? - the runtime ? Thanks

ML 



Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I don't know how to get the ESX server serial number through the vSphere API, but you can get it using plink.exe:

$User = "root"
$Password = "password"
$Command = 'esxcfg-info'

function Invoke-VMhostCommand {
  # This function assumes that plink.exe is in your path
  param([parameter(Mandatory=$true)][string] $VMHost,
        [parameter(Mandatory=$true)][string] $User,
        [parameter(Mandatory=$true)][string] $Password,
        [parameter(Mandatory=$true)][string] $Command)

  $plink = "plink.exe"
  $plinkoptions = " -v -batch -pw $Password"
  $remoteCommand = '"' + $Command + '"'
  $PlinkCommand = $plink + " " + $plinkoptions + " " + $User + "@" + $VMHost + " " + $remoteCommand
  $msg = Invoke-Expression -command $PlinkCommand
  $Report = "" | Select-Object Host,Output
  $Report.Host = $VMHost
  $Report.Output = $msg
  $Report
}

$Report = Get-VMHost | ForEach-Object {Invoke-VMHostCommand -VMHost $_.Name -User $User -Password $Password -Command $Command }
$Report | ForEach-Object { $_.Output = $_.Output | Select-String -pattern "Serial N" -casesensitive } 
$Report | Format-Table -AutoSize

Regards, Robert

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

I only need the WWN for the HBA adapters. I changed the triggers as follows.

Get-VMHost | Select Name, Version,

Build,

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

Manufacturer, Model, ProcessorType,

@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},

@{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="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}))}}

However the output only shows me the following below. In the Client is see 4 HBA names. See attached picture.

Name : XXXXXXXX

Version : 4.1.0

Build : 260247

Cluster Name : E3 - Production Cluster

Manufacturer : HP

Model : ProLiant BL680c G5

ProcessorType : Intel(R) Xeon(R) CPU E7330 @ 2.40GHz

HBA count : 2

FC Device : vmhba1,vmhba2

FC WWN : 5001438002218bd9,5001438002218bdb

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You want the PortWorldWideName property instead of the NodeWorldWideName property.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
ngerasim
Contributor
Contributor
Jump to solution

Modified.

Get-VMHost | Select Name, Version,

@{N="HBA count";E={($_| Get-VMHostHba | where {$_.Type -eq "FibreChannel"}).Count}},

@{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 $_.PortWorldWideName}))}}

However I now get the following output showing no details.

Name : epqvh306.XXXXXXXXXX

Version : 4.1.0

HBA count : 2

FC Device :

FC WWN :

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's most probably because the square brackets were eaten by the forum SW.

I attached the script.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos