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.
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
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
Hi
It works, but can we replace the VMNICS with just Number of Physical NIC instead.
thanks for the quick help.
Hey can we replace the NICS parameter, instead of VMNICS change it with just No. Of NICS.
Thanks.
You may want also add the VMotion network beside the Management network.
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
Thanks for that.
Good work. 😃
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!
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}},
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?
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;
The availability varies in the same way with other models from IBM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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?
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