Hi
I've tried the following but cannot get the number of VM CPU and Cores. What am I doing wrong?
Sure, try like this
$myCol = @()
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,HostName,VMName,VMSockets,VMCores,CPUSockets,CPUCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.HostName = $vmhost.Name
$VMSummary.VMName = $vm.Name
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
$VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
$myCol += $VMSummary
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Those lines should be.
These are actual values, not MoRefs (pointers)
$vmSummary.VMSockets = $vm.Config.Hardware.NumCPU
$vmSummary.VMCores = $vm.Config.Hardware.NumCoresPerSocket
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
For some reason this did not work:
$vmSummary.VMSockets = $vm.Config.Hardware.NumCPU
$vmSummary.VMCores = $vm.Config.Hardware.NumCoresPerSocket
This worked:
$vmSummary.VMSockets = $vm.NumCPU
but this didn't:
$vmSummary.VMCores = $vm.NumCoresPerSocket
Yes, that should be the $vmview variable instead of the $vm variable.
Like this
$myCol = @()
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,HostName,VMName,VMSockets,VMCores,CPUSockets,CPUCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.HostName = $vmhost.Name
$VMSummary.VMName = $vm.Name
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$myCol += $VMSummary
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI Luc,
Isn't it possible to get the Sockets and cores for both the hosts and VMs?
Sure, try like this
$myCol = @()
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost)){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,HostName,VMName,VMSockets,VMCores,CPUSockets,CPUCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.HostName = $vmhost.Name
$VMSummary.VMName = $vm.Name
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
$VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
$myCol += $VMSummary
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was it. Thanks!
If you have VMware Tools installed, you can do
$myCol = @()
foreach ($cluster in Get-Cluster)
{
foreach($vmhost in ($cluster | Get-VMHost))
{
foreach($vm in (Get-VM -Location $vmhost | where{$_.Guest.OSFullName -match "Red Hat"})){
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName,HostName,VMName,OS,VMSockets,VMCores,CPUSockets,CPUCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.HostName = $vmhost.Name
$VMSummary.VMName = $vm.Name
$VMSummary.OS = $vm.Guest.OSFullName
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
$VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
$myCol += $VMSummary
}
}
}
$myCol
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thats awesome! Thank you... I did not know that info was available for Get-VM thought one had to use Get-View.
Anywho, thanks again!
Hi,
I just found this nice script. I was wondering how to filter the vmsockets that are exceeding the cpusocket & maybe also in an nice format?
I am already happy with this script.
Many thanks in advance.
Cheers
Roberto
You can do something like this.
Not sure what you mean by the "nice format"
foreach ($cluster in Get-Cluster) {
foreach ($vmhost in ($cluster | Get-VMHost)) {
$vms = Get-VM -Location $vmhost|
where {$_.ExtensionData.Config.Hardware.NumCpu -gt $_.vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages}
foreach ($vm in $vms) {
$VMView = $vm | Get-View
$VMSummary = "" | Select ClusterName, HostName, VMName, VMSockets, VMCores, CPUSockets, CPUCores
$VMSummary.ClusterName = $cluster.Name
$VMSummary.HostName = $vmhost.Name
$VMSummary.VMName = $vm.Name
$VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
$VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
$VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
$VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
$myCol += $VMSummary
}
}
}
$myCol
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much. You pointed me in the right direction.
Cheers,
Roberto
I am getting the following error when trying to run this from both ISE and CLI 6.5R1 :
Exception has been thrown by the target of an invocation.
At H:\Scripts\VM_Sockets_Cores_Updated.ps1:6 char:11
+ $vms = Get-VM -Location $vmhost|
Can you attach the script you are using as a file to this thread?
The Attach button is in the lower right part of the edit window
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference