build 7bbbddf7 | content blog-content@c8490fa · 338 posts | profiles 20 · corpus 267 | 0 skipped | | format
apiVersion: soultec.ch/v1kind: Postmetadata: name: powercli-getting-the-usage-of-a-cluster locale: en labels: author: dario-doerflinger series: scripting capability/automation: 1.78 vendor/vmware: 0.88 annotations: source: blog-content/posts/en/powercli-getting-the-usage-of-a-cluster.md route: /en/insights/powercli-getting-the-usage-of-a-cluster/ schema: /nerd/schema/posts.json markdown: /en/insights/powercli-getting-the-usage-of-a-cluster.mdspec: title: Getting the Usage of a cluster date: 2018-06-04 author: dario-doerflinger locale: en summary: >- Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. capabilities: [automation] vendors: [vmware] series: scripting legacySlug: powercli-getting-the-usage-of-a-cluster migrated: 2026-08-24 draft: false sections: - body: | Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. One of those checks is a cluster-usage assessment. This helps us further down the road when advising the customer in ways to improve the resilience of his infrastructure. Now, I know the following script is a "snapshot" of the current usage and does not account for history or even query the vCenter's statistics on a given cluster. But that is okay, because a lot of the time the vCenter does not provide accurate information anyways. What is still missing from the script is a balancing of host resources. This script basically assumes that all hosts in a cluster are equal in terms of CPU and RAM resources. If they are not the percentage at the end of the script is not very accurate. **A big thanks to [LucD](http://www.lucd.info/) for pointing that out to me**. You can see our discussion on the matter in the VMware communities [here](https://communities.vmware.com/thread/568844). Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). If I can get around to it I will put some thought into how to address this in the script but in the meantime here it is with the mentioned caveats: ```powershell $clusters = get-cluster $myClusters = @() foreach ($cluster in $clusters) { $hosts = $cluster |get-vmhost [double]$cpuAverage = 0 [double]$memAverage = 0 Write-Host $cluster foreach ($esx in $hosts) { Write-Host $esx [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg) $cpuAverage = $cpuAverage + $esxiCPUavg [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg) $memAverage = $memAverage + $esxiMEMavg } $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1) $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1) $ClusterInfo = "" | Select-Object Name, CPUAvg, MEMAvg $ClusterInfo.Name = $cluster.Name $ClusterInfo.CPUAvg = $cpuAverage $ClusterInfo.MEMAvg = $memAverage $myClusters += $ClusterInfo } $myClusters ``` Here is a picture of the expected output: ![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)status: corpus: 267 alsoLike: - {ref: posts/vmware-explore-las-vegas-hackathon-2025, score: 1.00} - {ref: posts/vmware-hackathon-2024-project, score: 1.00} - {ref: solutions/vmware/vmware-cloud-foundation/addon/application-services, score: 0.60}
{ "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": { "name": "powercli-getting-the-usage-of-a-cluster", "locale": "en", "labels": { "author": "dario-doerflinger", "series": "scripting", "capability/automation": "1.78", "vendor/vmware": "0.88" }, "annotations": { "source": "blog-content/posts/en/powercli-getting-the-usage-of-a-cluster.md", "route": "/en/insights/powercli-getting-the-usage-of-a-cluster/", "schema": "/nerd/schema/posts.json", "markdown": "/en/insights/powercli-getting-the-usage-of-a-cluster.md" } }, "spec": { "title": "Getting the Usage of a cluster", "date": "2018-06-04", "author": "dario-doerflinger", "locale": "en", "summary": "Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start.", "capabilities": [ "automation" ], "vendors": [ "vmware" ], "series": "scripting", "legacySlug": "powercli-getting-the-usage-of-a-cluster", "migrated": "2026-08-24", "draft": false }, "sections": [ { "body": "Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. One of those checks is a cluster-usage assessment. This helps us further down the road when advising the customer in ways to improve the resilience of his infrastructure.\n\nNow, I know the following script is a \"snapshot\" of the current usage and does not account for history or even query the vCenter's statistics on a given cluster. But that is okay, because a lot of the time the vCenter does not provide accurate information anyways.\n\nWhat is still missing from the script is a balancing of host resources. This script basically assumes that all hosts in a cluster are equal in terms of CPU and RAM resources. If they are not the percentage at the end of the script is not very accurate. **A big thanks to [LucD](http://www.lucd.info/) for pointing that out to me**. You can see our discussion on the matter in the VMware communities [here](https://communities.vmware.com/thread/568844).\n\nUpdate: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). \nIf I can get around to it I will put some thought into how to address this in the script but in the meantime here it is with the mentioned caveats:\n\n```powershell\n$clusters = get-cluster\n$myClusters = @()\nforeach ($cluster in $clusters) {\n $hosts = $cluster |get-vmhost\n\n [double]$cpuAverage = 0\n [double]$memAverage = 0\n\n Write-Host $cluster\n foreach ($esx in $hosts) {\n Write-Host $esx\n [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg)\n $cpuAverage = $cpuAverage + $esxiCPUavg\n\n [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg)\n $memAverage = $memAverage + $esxiMEMavg\n }\n $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1)\n $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1)\n $ClusterInfo = \"\" | Select-Object Name, CPUAvg, MEMAvg\n $ClusterInfo.Name = $cluster.Name\n $ClusterInfo.CPUAvg = $cpuAverage\n $ClusterInfo.MEMAvg = $memAverage\n $myClusters += $ClusterInfo\n}\n$myClusters\n```\n\nHere is a picture of the expected output:\n\n![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)" } ], "status": { "corpus": 267, "alsoLike": [ { "ref": "posts/vmware-explore-las-vegas-hackathon-2025", "score": "1.00" }, { "ref": "posts/vmware-hackathon-2024-project", "score": "1.00" }, { "ref": "solutions/vmware/vmware-cloud-foundation/addon/application-services", "score": "0.60" } ] }}
apiVersion = "soultec.ch/v1"kind = "Post"[metadata]name = "powercli-getting-the-usage-of-a-cluster"locale = "en"[metadata.labels]author = "dario-doerflinger"series = "scripting""capability/automation" = "1.78""vendor/vmware" = "0.88"[metadata.annotations]source = "blog-content/posts/en/powercli-getting-the-usage-of-a-cluster.md"route = "/en/insights/powercli-getting-the-usage-of-a-cluster/"schema = "/nerd/schema/posts.json"markdown = "/en/insights/powercli-getting-the-usage-of-a-cluster.md"[spec]title = "Getting the Usage of a cluster"date = 2018-06-04author = "dario-doerflinger"locale = "en"summary = "Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start."capabilities = ["automation"]vendors = ["vmware"]series = "scripting"legacySlug = "powercli-getting-the-usage-of-a-cluster"migrated = 2026-08-24draft = false[[sections]]body = '''Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. One of those checks is a cluster-usage assessment. This helps us further down the road when advising the customer in ways to improve the resilience of his infrastructure.Now, I know the following script is a "snapshot" of the current usage and does not account for history or even query the vCenter's statistics on a given cluster. But that is okay, because a lot of the time the vCenter does not provide accurate information anyways.What is still missing from the script is a balancing of host resources. This script basically assumes that all hosts in a cluster are equal in terms of CPU and RAM resources. If they are not the percentage at the end of the script is not very accurate. **A big thanks to [LucD](http://www.lucd.info/) for pointing that out to me**. You can see our discussion on the matter in the VMware communities [here](https://communities.vmware.com/thread/568844).Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). If I can get around to it I will put some thought into how to address this in the script but in the meantime here it is with the mentioned caveats:```powershell$clusters = get-cluster$myClusters = @()foreach ($cluster in $clusters) { $hosts = $cluster |get-vmhost [double]$cpuAverage = 0 [double]$memAverage = 0 Write-Host $cluster foreach ($esx in $hosts) { Write-Host $esx [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg) $cpuAverage = $cpuAverage + $esxiCPUavg [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg) $memAverage = $memAverage + $esxiMEMavg } $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1) $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1) $ClusterInfo = "" | Select-Object Name, CPUAvg, MEMAvg $ClusterInfo.Name = $cluster.Name $ClusterInfo.CPUAvg = $cpuAverage $ClusterInfo.MEMAvg = $memAverage $myClusters += $ClusterInfo}$myClusters```Here is a picture of the expected output:![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)'''[status]corpus = 267[[status.alsoLike]]ref = "posts/vmware-explore-las-vegas-hackathon-2025"score = "1.00"[[status.alsoLike]]ref = "posts/vmware-hackathon-2024-project"score = "1.00"[[status.alsoLike]]ref = "solutions/vmware/vmware-cloud-foundation/addon/application-services"score = "0.60"
<?xml version="1.0" encoding="UTF-8"?><manifest kind="Post"> <apiVersion>soultec.ch/v1</apiVersion> <metadata> <name>powercli-getting-the-usage-of-a-cluster</name> <locale>en</locale> <labels> <author>dario-doerflinger</author> <series>scripting</series> <entry key="capability/automation">1.78</entry> <entry key="vendor/vmware">0.88</entry> </labels> <annotations> <source>blog-content/posts/en/powercli-getting-the-usage-of-a-cluster.md</source> <route>/en/insights/powercli-getting-the-usage-of-a-cluster/</route> <schema>/nerd/schema/posts.json</schema> <markdown>/en/insights/powercli-getting-the-usage-of-a-cluster.md</markdown> </annotations> </metadata> <spec> <title>Getting the Usage of a cluster</title> <date>2018-06-04</date> <author>dario-doerflinger</author> <locale>en</locale> <summary>Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start.</summary> <capabilities> <item>automation</item> </capabilities> <vendors> <item>vmware</item> </vendors> <series>scripting</series> <legacySlug>powercli-getting-the-usage-of-a-cluster</legacySlug> <migrated>2026-08-24</migrated> <draft>false</draft> </spec> <sections> <section> <body>Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. One of those checks is a cluster-usage assessment. This helps us further down the road when advising the customer in ways to improve the resilience of his infrastructure.Now, I know the following script is a "snapshot" of the current usage and does not account for history or even query the vCenter's statistics on a given cluster. But that is okay, because a lot of the time the vCenter does not provide accurate information anyways.What is still missing from the script is a balancing of host resources. This script basically assumes that all hosts in a cluster are equal in terms of CPU and RAM resources. If they are not the percentage at the end of the script is not very accurate. **A big thanks to [LucD](http://www.lucd.info/) for pointing that out to me**. You can see our discussion on the matter in the VMware communities [here](https://communities.vmware.com/thread/568844).Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). If I can get around to it I will put some thought into how to address this in the script but in the meantime here it is with the mentioned caveats:```powershell$clusters = get-cluster$myClusters = @()foreach ($cluster in $clusters) { $hosts = $cluster |get-vmhost [double]$cpuAverage = 0 [double]$memAverage = 0 Write-Host $cluster foreach ($esx in $hosts) { Write-Host $esx [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg) $cpuAverage = $cpuAverage + $esxiCPUavg [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg) $memAverage = $memAverage + $esxiMEMavg } $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1) $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1) $ClusterInfo = "" | Select-Object Name, CPUAvg, MEMAvg $ClusterInfo.Name = $cluster.Name $ClusterInfo.CPUAvg = $cpuAverage $ClusterInfo.MEMAvg = $memAverage $myClusters += $ClusterInfo}$myClusters```Here is a picture of the expected output:![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp) </body> </section> </sections> <status> <corpus>267</corpus> <alsoLike> <item> <ref>posts/vmware-explore-las-vegas-hackathon-2025</ref> <score>1.00</score> </item> <item> <ref>posts/vmware-hackathon-2024-project</ref> <score>1.00</score> </item> <item> <ref>solutions/vmware/vmware-cloud-foundation/addon/application-services</ref> <score>0.60</score> </item> </alsoLike> </status></manifest>
Scripting · 2018-06-04

Getting the Usage of a cluster

Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start.

2018-06-04Date
Dario DörflingerAuthor
2Min read
Topics Automation 1.78
Vendors VMware 0.88

This post is from 2018. It stays online because people still look for it, but it describes the products as they were then.

Our customers sometimes call us in to check their environment. Because this happens quite often we created a basic checklist on what checks we do when we start. One of those checks is a cluster-usage assessment. This helps us further down the road when advising the customer in ways to improve the resilience of his infrastructure.

Now, I know the following script is a “snapshot” of the current usage and does not account for history or even query the vCenter’s statistics on a given cluster. But that is okay, because a lot of the time the vCenter does not provide accurate information anyways.

What is still missing from the script is a balancing of host resources. This script basically assumes that all hosts in a cluster are equal in terms of CPU and RAM resources. If they are not the percentage at the end of the script is not very accurate. A big thanks to LucD for pointing that out to me. You can see our discussion on the matter in the VMware communities here.

Update: this script is now published at GitHub.
If I can get around to it I will put some thought into how to address this in the script but in the meantime here it is with the mentioned caveats:

$clusters = get-cluster
$myClusters = @()
foreach ($cluster in $clusters) {
    $hosts = $cluster |get-vmhost

    [double]$cpuAverage = 0
    [double]$memAverage = 0

    Write-Host $cluster
    foreach ($esx in $hosts) {
        Write-Host $esx
        [double]$esxiCPUavg = [double]($esx | Select-Object @{N = 'cpuAvg'; E = {[double]([math]::Round(($_.CpuUsageMhz) / ($_.CpuTotalMhz) * 100, 2))}} |Select-Object -ExpandProperty cpuAvg)
        $cpuAverage = $cpuAverage + $esxiCPUavg

        [double]$esxiMEMavg = [double]($esx | Select-Object @{N = 'memAvg'; E = {[double]([math]::Round(($_.MemoryUsageMB) / ($_.MemoryTotalMB) * 100, 2))}} |select-object -ExpandProperty memAvg)
        $memAverage = $memAverage + $esxiMEMavg
    }
    $cpuAverage = [math]::Round(($cpuAverage / ($hosts.count) ), 1)
    $memAverage = [math]::Round(($memAverage / ($hosts.count) ), 1)
    $ClusterInfo = "" | Select-Object Name, CPUAvg, MEMAvg
    $ClusterInfo.Name = $cluster.Name
    $ClusterInfo.CPUAvg = $cpuAverage
    $ClusterInfo.MEMAvg = $memAverage
    $myClusters += $ClusterInfo
}
$myClusters

Here is a picture of the expected output:

image003

You might also like