VMware Cloud Community
bernworx
Enthusiast
Enthusiast
Jump to solution

Export Datacenter Hosts Information

Hi

Anyone has a PowerCLI that can export the following info to CSV...

DC, CLUSTER, HOSTNAME, MANAGEMENT IP, MANUFACTURER, MODEL, CPU CORES, PROCESSOR TYPE, CPU SOCKETS, CORES PER SOCKET, MEMORY, NICS, TIME ZONE, VERSION    BUILD

That will be a good help.

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I modified the script to display the vMotion IP address and the number of nics. While searching for the vMotion IP address, I also found a better way to find the management IP address. So I changed that as well.

Get-Datacenter |
ForEach-Object {
  if ($_) {
    $Datacenter = $_
    $Datacenter |
    Get-VMHost |
    Select-Object -Property @{Name="Datacenter";Expression={$Datacenter.Name}},
    @{Name="Cluster";Expression={$_.Parent.Name}},
    @{Name="HostName";Expression={$_.Name}},
    @{Name="ManagementIP";Expression={
      ($_ | Get-VMHostNetworkAdapter |
        Where-Object {$_.GetType().Name -eq "HostVMKernelVirtualNicImpl" -and $_.ManagementTrafficEnabled}).IP
    }},
    @{Name="vMotionIP";Expression={
      ($_ | Get-VMHostNetworkAdapter |
        Where-Object {$_.GetType().Name -eq "HostVMKernelVirtualNicImpl" -and $_.VMotionEnabled}).IP
    }},
    Manufacturer,
    Model,
    NumCpu,
    ProcessorType,
    @{Name="CpuSockets";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    @{Name="CoresPerSocket";Expression={
      $_.ExtensionData.Hardware.CpuInfo.NumCpuCores/$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages
    }},
    MemoryTotalGB,
    @{Name="NumNics";Expression={@($_.NetworkInfo.PhysicalNic).Count}},
    @{Name="TimeZone";Expression={$_.ExtensionData.Config.DateTimeInfo.TimeZone.Name}},
    Version,
    Build    
  }
} |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture 

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
12 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The following PowerCLI script will export all the requested host information to a file VMHostInfo.csv:

Get-Datacenter |
ForEach-Object {
  if ($_) {
    $Datacenter = $_
    $Datacenter |
    Get-VMHost |
    Select-Object -Property @{Name="Datacenter";Expression={$Datacenter.Name}},
    @{Name="Cluster";Expression={$_.Parent.Name}},
    @{Name="HostName";Expression={$_.Name}},
    @{Name="ManagementIP";Expression={($_ | Get-VMHostNetworkAdapter | Where-Object {$_.Name -eq "vmk0"}).IP}},
    Manufacturer,
    Model,
    NumCpu,
    ProcessorType,
    @{Name="CpuSockets";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    @{Name="CoresPerSocket";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuCores/$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    MemoryTotalGB,
    @{Name="Nics";Expression={$_.NetworkInfo.PhysicalNic}},
    @{Name="TimeZone";Expression={$_.ExtensionData.Config.DateTimeInfo.TimeZone.Name}},
    Version,
    Build    
  }
} |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture 

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

Hi

It works, but can we replace the VMNICS with just Number of Physical NIC instead.

thanks for the quick help.

0 Kudos
bernworx
Enthusiast
Enthusiast
Jump to solution

Hey can we replace the NICS parameter, instead of VMNICS change it with just No. Of NICS.

Thanks.

0 Kudos
bernworx
Enthusiast
Enthusiast
Jump to solution

You may want also add the VMotion network beside the Management network.

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I modified the script to display the vMotion IP address and the number of nics. While searching for the vMotion IP address, I also found a better way to find the management IP address. So I changed that as well.

Get-Datacenter |
ForEach-Object {
  if ($_) {
    $Datacenter = $_
    $Datacenter |
    Get-VMHost |
    Select-Object -Property @{Name="Datacenter";Expression={$Datacenter.Name}},
    @{Name="Cluster";Expression={$_.Parent.Name}},
    @{Name="HostName";Expression={$_.Name}},
    @{Name="ManagementIP";Expression={
      ($_ | Get-VMHostNetworkAdapter |
        Where-Object {$_.GetType().Name -eq "HostVMKernelVirtualNicImpl" -and $_.ManagementTrafficEnabled}).IP
    }},
    @{Name="vMotionIP";Expression={
      ($_ | Get-VMHostNetworkAdapter |
        Where-Object {$_.GetType().Name -eq "HostVMKernelVirtualNicImpl" -and $_.VMotionEnabled}).IP
    }},
    Manufacturer,
    Model,
    NumCpu,
    ProcessorType,
    @{Name="CpuSockets";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    @{Name="CoresPerSocket";Expression={
      $_.ExtensionData.Hardware.CpuInfo.NumCpuCores/$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages
    }},
    MemoryTotalGB,
    @{Name="NumNics";Expression={@($_.NetworkInfo.PhysicalNic).Count}},
    @{Name="TimeZone";Expression={$_.ExtensionData.Config.DateTimeInfo.TimeZone.Name}},
    Version,
    Build    
  }
} |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture 

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

Thanks for that.

Good work. 😃

0 Kudos
OwenW201110141
Contributor
Contributor
Jump to solution

This is a great script and works perfectly for me! Just one addition though - is it possible to also retrieve the serial number of the host in this code? I cant seem to find the serial number property object documented anywhere to try it out.

Thanks!

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the serial number of the hosts if you insert the following code before the "Version," line:

@{Name="SerialNumber";Expression={$_.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo |
Where-Object {$_.IdentifierType.Key -eq "Servicetag"} |
Select-Object -ExpandProperty IdentifierValue}},

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

Thanks Robert but it doesn’t seem to work 100% …

The script only returns a couple of serial numbers, from Dell hosts. Unfortunately I want serial numbers from IBM hosts.

Here is the code I am running:

-----------

Get-Datacenter |
ForEach-Object {
  if ($_) {
    $Datacenter = $_
    $Datacenter |
    Get-VMHost |
    Select-Object -Property @{Name="Datacenter";Expression={$Datacenter.Name}},
    @{Name="Cluster";Expression={$_.Parent.Name}},
    @{Name="HostName";Expression={$_.Name}},
    @{Name="ManagementIP";Expression={($_ | Get-VMHostNetworkAdapter | Where-Object {$_.Name -eq "vmk0"}).IP}},
    Manufacturer,
    Model,
    NumCpu,
    ProcessorType,
    @{Name="CpuSockets";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    @{Name="CoresPerSocket";Expression={$_.ExtensionData.Hardware.CpuInfo.NumCpuCores/$_.ExtensionData.Hardware.CpuInfo.NumCpuPackages}},
    MemoryTotalGB,
    @{Name="Nics";Expression={$_.NetworkInfo.PhysicalNic}},
    @{Name="TimeZone";Expression={$_.ExtensionData.Config.DateTimeInfo.TimeZone.Name}},
@{Name="SerialNumber";Expression={$_.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo |
Where-Object {$_.IdentifierType.Key -eq "Servicetag"} |
Select-Object -ExpandProperty IdentifierValue}},
    Version,
    Build   
  }
} |
Export-Csv -Path VMHostInfo.csv -NoTypeInformation -UseCulture

---------

Any other ideas?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid that the availability of the serial number in that property depends if the HW vendor made that information available according the specs that VMware expects it to be.

With IBM HW that is unfortunately not always the case;

  • most x3650 M2 have the serial number in that property,
  • some older x3650 M3 do not have the serial number in that property
  • with the x3650 M3 I never saw the serial number in that property

The availability varies in the same way with other models from IBM


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

0 Kudos
OwenW201110141
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for your input. It is possible to see the serial number from within vSphere per host. The hosts are x3850's and fairly new.

Is it simply down to the fact that the vendor not doing things as per VMWare's spec then?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you mean under the Hardware Status tab in the vSphere client ?

I suspect that info is obtained through CIM, while the property is not.

You can use the CIM interface as well from PowerCLI. There are a number of samples in this community and on some blogs.


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

0 Kudos