[PowerCLI] Show ESX cluster CPU/Mem averages

As a follow-up on my earlier [PowerCLI] Report ESX vCPU vs pCPU & Memory ratio script, I created a script that only shows average CPU and Memory usages per Cluster.
This brief cluster overview is (for example) usable for management reporting.

See [PowerCLI] Report ESX vCPU vs pCPU & Memory ratio for more information about how to read the output.

<#
.SYNOPSIS
  Shows average cluster resources usage
 
.DESCRIPTION
  The script shows information about vCPU to pCPU ratio and memory usage/commitment. Excludes hosts in Maintenance.
  Based on CheckResources.ps1 script.
 
.PARAMETER <Parameter_Name>
  None
.INPUTS
  None 
.OUTPUTS
  Table output in the 5 columns.
 
.NOTES
  Version:        1.0
  Author:         Daniel Tromp	
  Creation Date:  23-06-2014
  Purpose/Change: Get CPU Ratio and Memory usage/commitment
  
.EXAMPLE
  ./CheckClusterAverages.ps1
#>
$array = @();
Foreach ($Cluster in (Get-Cluster |Sort Name)){
     $ClusCPUratio  = 0
     $ClusNumvCPUs  = 0
     $ClusNumpCPUs  = 0
     $ClusNumvMem   = 0
     $ClusGrantMem  = 0  
     $ClusUsageMem  = 0
     $ClusMemUsable = 0
     $ClusMemUsed   = 0
     Foreach ($ESXHost in ($Cluster |Get-VMHost -State Connected |Sort Name)){
         $HostNumvCPUs = 0
	     $HostNumvMem  = 0
         Foreach ($VM in ($ESXHost |Get-VM)){
	         $HostNumvCPUs += ($VM).NumCpu
	         $HostNumvMem  += ($VM).MemoryGB
         }	
         $ClusNumvCPUs  += $HostNumvCPUs
         $ClusNumpCPUs  += ($ESXHost).NumCpu
	     $ClusMemUsable += ($ESXHost | Get-View).Hardware.MemorySize/1GB
	     $ClusNumvMem   += $HostNumvMem
	     $ClusMemUsed   += ($ESXHost).MemoryUsageGB
     }
     $ClusCPUratio   = "{0:N0}" -f ($ClusNumvCPUs / $ClusNumpCPUs)
     $ClusGrantMem   = "{0:N0}" -f ($ClusNumvMem/$ClusMemUsable*100)
     $ClusUsageMem   = "{0:N0}" -f ($ClusMemUsed/$ClusMemUsable*100)
	
     $HostVar = @{Cluster=$($Cluster.name); HostCount=($Cluster|Get-VMHost -State Connected).Count; AvgCPURatio=$ClusCPUratio + ":1"; AvgMemGranted=$ClusGrantMem + "%"; AvgMemUsed=$ClusUsageMem + "%"} 
     $array +=  New-Object PSObject -Property $HostVar
}
$array | Select-Object Cluster,HostCount,AvgCPURatio,AvgMemGranted,AvgMemUsed | Format-Table -AutoSize

Output:
CheckClusterAverages

Leave a Reply

Your email address will not be published. Required fields are marked *