Hello everyone,
I would like to get a report of the hosts contained in a cluster using PowerCLI containing the following information:
Total CPU
Total CPU Used
Total CPU free
Total Core
Total Core Used
Total Core free
Total VMs that could be installed using configuration 1:4
I have been able to get the total, used and free CPUs, but I can't get the cores information and VMs
Could you please enlighten me and show me how to do it?
I moved the Get-VM inside the loop, and it seems to work for me
$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
$Output=@()
ForEach ($vmhost in $vmhosts)
{
$vms = Get-VM -Location $vmhost
$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms | ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}
$temp= New-Object psobject
$temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
$temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
$temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
$temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
$temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
$Output+=$temp
}
$output
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
Get-Cluster -PipelineVariable cluster | ForEach-Object -Process {
Get-VMHost -Location $cluster |
ForEach-Object -Process {
$numCpuSum = (Get-VM -Location $_ | Measure-Object -Property NumCpu -Sum).Sum
New-Object -TypeName PSObject -Property @{
Cluster = $cluster.Name
VMHost = $_.Name
PhysicalThreads = $_.ExtensionData.Hardware.CpuInfo.NumCpuCores
vCPUs = $numCpuSum
Ratio = if ($numCpuSum -gt 0) {
"$("{0:N2}" -f ($numCpuSum/$_.ExtensionData.Hardware.CpuInfo.NumCpuCores))" + ":1"
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What do you mean by "cores used"?
Is that the number of vCPU assigned to VMs running in that cluster?
Or do you mean realtime performance metrics showing core cpu utilisation?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry I explained wrong, what I intend to do is to make an estimate based on the cores that have the processors and the cores consumed , based on that estimate whose VMs are configured Core per Socket 1:4.
I have created this script but I can't find the error, could you please help me?
param(
[Parameter(Mandatory = $false)]
[String]$cluster,
$vmhosts="*"
)
$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
$vms=Get-VM
$Output=@()
ForEach ($vmhost in $vmhosts)
{
$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms |Where-Object {$_.vmhost -like $vmhost}|ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}
$temp= New-Object psobject
$temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
$temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
$temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
$temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
$temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
$Output+=$temp
}
$output
I moved the Get-VM inside the loop, and it seems to work for me
$vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
$Output=@()
ForEach ($vmhost in $vmhosts)
{
$vms = Get-VM -Location $vmhost
$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms | ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}
$temp= New-Object psobject
$temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
$temp| Add-Member -MemberType Noteproperty "Cluster" -value $vmhost.parent.name
$temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
$temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
$temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
$Output+=$temp
}
$output
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I get the following error:
Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At D:\vCollect-Reports\Untitled1.ps1:1 char:44
+ $vmhosts=get-cluster $cluster | Get-VMHost $vmhosts
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost
I have updated to the latest version, but it gives the same error.
I left out your parameter definitions, you will have to add them
param(
[Parameter(Mandatory = $false)]
[String]$cluster,
$vmhosts="*"
)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What parameters should I change so that the script runs on all vCenter clusters, and not one by one?
You could do something like this
Get-Cluster -PipelineVariable cluster | ForEach-Object -Process {
Get-VMHost -Location $cluster |
ForEach-Object -Process {
$numCpuSum = (Get-VM -Location $_ | Measure-Object -Property NumCpu -Sum).Sum
New-Object -TypeName PSObject -Property @{
Cluster = $cluster.Name
VMHost = $_.Name
PhysicalThreads = $_.ExtensionData.Hardware.CpuInfo.NumCpuCores
vCPUs = $numCpuSum
Ratio = if ($numCpuSum -gt 0) {
"$("{0:N2}" -f ($numCpuSum/$_.ExtensionData.Hardware.CpuInfo.NumCpuCores))" + ":1"
}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much!!!!!