Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sam-Martin/1dd99c4c6597a447461b to your computer and use it in GitHub Desktop.
Save Sam-Martin/1dd99c4c6597a447461b to your computer and use it in GitHub Desktop.
Get VMWare Cluster Contention
foreach($cluster in Get-Cluster){
# Get host memory free
$vmHostObj = $cluster | Get-VMHost
$totalVMHostMemory = [int]$($vmHostObj | measure-object -property MemoryTotalGB -sum).sum;
$totalVMHostMemoryFree = $($vmHostObj | %{$_.MemoryTotalGB - $_.MemoryUsageGB} | measure-object -sum).sum;
$highestHostMemoryTotal = $($vmHostObj | sort-object -property MemoryTotalGB | select -last 1).MemoryTotalGB;
$totalVMHostCPU = [int]$($vmHostObj | measure-object -property CPUTotalMhz -sum).sum;
$totalVMHostCPUFree = $($vmHostObj | %{$_.CPUTotalMhz - $_.CPUUsageMhz} | measure-object -sum).sum;
$highestHostCPUTotal = $($vmHostObj | sort-object -property CPUTotalMhz | select -last 1).CPUTotalMhz;
New-Object PSObject -Property @{
Cluster= $cluster.Name
TotalVMHostCPUMhz = $totalVMHostCPU
TotalVMhostCPUFree = $totalVMHostCPUFree
TotalVMHostMemory = $totalVMHostMemory
TotalVMHostMemoryFree = $totalVMHostMemoryFree
"Number of hosts that can be lost (memory)" = $([Math]::Round($totalVMHostMemoryFree/$highestHostMemoryTotal,2))
"Number of hosts that can be lost (CPU)" = $([Math]::Round($totalVMHostCPUFree/$highestHostCPUTotal,2))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment