Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created September 7, 2020 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vMarkusK/75b99ed5f78ab3b515cce42ade798547 to your computer and use it in GitHub Desktop.
Save vMarkusK/75b99ed5f78ab3b515cce42ade798547 to your computer and use it in GitHub Desktop.
This VMware PowerCLI Script gathers the current SLIs of the given vSphere Cluster. The values are only a snapshot of the current state, no statistics are processed (so far).
function Get-ClusterSLO {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
Twitter: @VMarkus_K
Private Blog: mycloudrevolution.com
===========================================================================
Changelog:
2020.08 ver 1.0 Base Release
===========================================================================
External Code Sources:
-
===========================================================================
Tested Against Environment:
vSphere Version: 6.7 U3
PowerCLI Version: PowerCLI 12.0.0
PowerShell Version: 5.1
OS Version: Windows Server 2016
===========================================================================
Keywords vSphere, ESXi, VM, Sizing
===========================================================================
.DESCRIPTION
This VMware PowerCLI Script gathers the current SLIs of the given vSphere Cluster.
The values are only a snapshot of the current state, no statistics are processed (so far).
.Example
Get-Cluster -Name $ClusterName | Get-ClusterSLO
.PARAMETER Cluster
vSphere Cluster
#Requires PS -Version 5.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$true, Position=0)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.ComputeResourceImpl] $Cluster
)
Process {
$MyView = @()
foreach ($Object in $Cluster) {
# CLuster Inventory
$ClusterVMs = $Object | Get-VM -Verbose:$False
$ClusterVMsPoweredOn = $ClusterVMs | where {$_.PowerState -eq "PoweredOn"}
$ClusterDatastores = $Object | Get-Datastore -Verbose:$False
$ClusterHosts = $Object | Get-VMHost -Verbose:$False
# Host Memory
$HostsAverageMemoryUsageGB = [math]::round( ($ClusterHosts | Measure-Object -Average -Property MemoryUsageGB).Average,1 )
$HostsAverageMemoryUsage = $([math]::round( (($ClusterHosts | Measure-Object -Average -Property MemoryUsageGB).Average / ($ClusterHosts | Measure-Object -Average -Property MemoryTotalGB).Average) * 100,1 ))
$HostsAverageCpuUsageMhz = [math]::round( ($ClusterHosts | Measure-Object -Average -Property CpuUsageMhz).Average,1 )
$HostsAverageCpuUsage = $([math]::round( (($ClusterHosts | Measure-Object -Average -Property CpuUsageMhz).Average / ($ClusterHosts | Measure-Object -Average -Property CpuTotalMhz).Average) * 100,1 ))
# Cluster CPU Calculation
$VMvCPUs = ($ClusterVMs | Measure-Object -Sum -Property NumCpu).sum
$VMAvgCPUs = [math]::round(($ClusterVMs | Measure-Object -Average -Property NumCpu).Average,1 )
$VMAvgMemGB = [math]::round(($ClusterVMs | Measure-Object -Average -Property MemoryGB).Average,1 )
$LogicalThreads = $Object.ExtensionData.Summary.NumCpuThreads
$CpuCores = $Object.ExtensionData.Summary.NumCpuCores
$vCPUlCPUratio = [math]::round( $VMvCPUs / $LogicalThreads,1 )
$CpuTotalMhz = $Object.ExtensionData.Summary.UsageSummary.TotalCpuCapacityMhz
$CpuDemandMhz = $Object.ExtensionData.Summary.UsageSummary.CpuDemandMhz
$CPUUsage = [math]::round( ($CpuDemandMhz / $CpuTotalMhz) * 100 ,1 )
# Cluster Memory Calculation
$AllocatedVMMemoryGB = [math]::round( ($ClusterVMs | Measure-Object -Sum -Property MemoryGB).sum )
$PhysicalMemory = [math]::round( $Object.ExtensionData.Summary.TotalMemory / 1073741824,1 )
$MemoryUsage = [math]::round( ($AllocatedVMMemoryGB / $PhysicalMemory) * 100 ,1 )
# Create Global Report
$SizingReport = [PSCustomObject] @{
HAEnabled = $Object.HAEnabled
DrsEnabled = $Object.DrsEnabled
ActiveVMs = $ClusterVMsPoweredOn.count
VMs = $ClusterVMs.count
VMsAvgCPU = $VMAvgCPUs
VMsAvgMemGB = $VMAvgMemGB
Hosts = $Object.ExtensionData.Summary.NumHosts
HostsAverageMemoryUsageGB = $HostsAverageMemoryUsageGB
HostsAverageMemoryUsagePercent = "$HostsAverageMemoryUsage %"
HostsAverageCpuUsageMhz = $HostsAverageCpuUsageMhz
HostsAverageCpuUsagePercent = "$HostsAverageCpuUsage %"
ClusterPhysicalMemoryGB = $PhysicalMemory
ClusterAllocatedMemoryGB = $AllocatedVMMemoryGB
ClusterAllocatedMemoryPercentage = "$MemoryUsage %"
ClusterPhysicalCPUCores = $CpuCores
ClusterLogicalCPUThreads = $LogicalThreads
ClusterAllocatedCPU = "$vCPUlCPUratio : 1" #Logical Threads
ClusterPhysicalCPUMHz = $CpuTotalMhz
ClusterUsedCPUMHz = $CpuDemandMhz
ClusterUsedCPUPercentage = $CPUUsage
}
$MyView += $SizingReport
}
}
End {
$MyView
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment