build 6ddc7a35 | content blog-content@417154f · 338 posts | profiles 32 · corpus 315 | ● 0 skipped | format run

$ soultec get post/powercli-getting-the-usage-of-a-cluster -o yaml$ soultec get post/powercli-getting-the-usage-of-a-cluster -o json$ soultec get post/powercli-getting-the-usage-of-a-cluster -o toml$ soultec get post/powercli-getting-the-usage-of-a-cluster -o xml$ python3 powercli-getting-the-usage-of-a-cluster.pyPS> ./powercli-getting-the-usage-of-a-cluster.ps1$ go run powercli-getting-the-usage-of-a-cluster.go$ node powercli-getting-the-usage-of-a-cluster.js

apiVersion: soultec.ch/v1kind: Postmetadata: name: powercli-getting-the-usage-of-a-cluster locale: en labels: author: dario-doerflinger series: scripting capability/automation: 1.81 vendor/vmware: 0.98 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: 315 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/business-operations, score: 0.60} search: /en/search.json
{ "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.81, "vendor/vmware": 0.98 }, "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": 315, "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/business-operations", "score": "0.60" } ], "search": "/en/search.json" }}
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.81"vendor/vmware" = 0.98[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[[spec.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 = 315search = "/en/search.json"[[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/business-operations"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.81</entry> <entry key="vendor/vmware">0.98</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> <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> </spec> <status> <corpus>315</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/business-operations</ref> <score>0.60</score> </item> </alsoLike> <search>/en/search.json</search> </status></manifest>
# Code generated by the soultec.ch build. DO NOT EDIT.import jsonPAGE = { "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.81, "vendor/vmware": 0.98, }, "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" "\n" "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.\n" "\n" "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).\n" "\n" "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). \n" "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:\n" "\n" "```powershell\n" "$clusters = get-cluster\n" "$myClusters = @()\n" "foreach ($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" "\n" "Here is a picture of the expected output:\n" "\n" "![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)" ), }, ], }, "status": { "corpus": 315, "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/business-operations", "score": "0.60", }, ], "search": "/en/search.json", },}if __name__ == "__main__": print(json.dumps(PAGE, indent=2, ensure_ascii=False))
# Code generated by the soultec.ch build. DO NOT EDIT.$Page = [ordered]@{ apiVersion = 'soultec.ch/v1' kind = 'Post' metadata = [ordered]@{ name = 'powercli-getting-the-usage-of-a-cluster' locale = 'en' labels = [ordered]@{ author = 'dario-doerflinger' series = 'scripting' 'capability/automation' = 1.81 'vendor/vmware' = 0.98 } annotations = [ordered]@{ 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 = [ordered]@{ 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 = @( [ordered]@{ 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 = [ordered]@{ corpus = 315 alsoLike = @( [ordered]@{ ref = 'posts/vmware-explore-las-vegas-hackathon-2025' score = '1.00' } [ordered]@{ ref = 'posts/vmware-hackathon-2024-project' score = '1.00' } [ordered]@{ ref = 'solutions/vmware/vmware-cloud-foundation/addon/business-operations' score = '0.60' } ) search = '/en/search.json' }}$Page | ConvertTo-Json -Depth 32
// Code generated by the soultec.ch build. DO NOT EDIT.package mainimport ( "encoding/json" "os")var page = map[string]any{ "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": map[string]any{ "name": "powercli-getting-the-usage-of-a-cluster", "locale": "en", "labels": map[string]any{ "author": "dario-doerflinger", "series": "scripting", "capability/automation": 1.81, "vendor/vmware": 0.98, }, "annotations": map[string]any{ "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": map[string]any{ "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": []any{"automation"}, "vendors": []any{"vmware"}, "series": "scripting", "legacySlug": "powercli-getting-the-usage-of-a-cluster", "migrated": "2026-08-24", "draft": false, "sections": []any{ map[string]any{ "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" + "\n" + "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.\n" + "\n" + "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).\n" + "\n" + "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). \n" + "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:\n" + "\n" + "```powershell\n" + "$clusters = get-cluster\n" + "$myClusters = @()\n" + "foreach ($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" + "\n" + "Here is a picture of the expected output:\n" + "\n" + "![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)", }, }, }, "status": map[string]any{ "corpus": 315, "alsoLike": []any{ map[string]any{ "ref": "posts/vmware-explore-las-vegas-hackathon-2025", "score": "1.00", }, map[string]any{ "ref": "posts/vmware-hackathon-2024-project", "score": "1.00", }, map[string]any{ "ref": "solutions/vmware/vmware-cloud-foundation/addon/business-operations", "score": "0.60", }, }, "search": "/en/search.json", },}func main() { enc := json.NewEncoder(os.Stdout) enc.SetEscapeHTML(false) enc.SetIndent("", " ") if err := enc.Encode(page); err != nil { os.Exit(1) }}
// Code generated by the soultec.ch build. DO NOT EDIT.const page = { 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.81, "vendor/vmware": 0.98, }, 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" + "\n" + "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.\n" + "\n" + "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).\n" + "\n" + "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). \n" + "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:\n" + "\n" + "```powershell\n" + "$clusters = get-cluster\n" + "$myClusters = @()\n" + "foreach ($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" + "\n" + "Here is a picture of the expected output:\n" + "\n" + "![image003](/blog-assets/powercli-getting-the-usage-of-a-cluster/01.webp)", }, ], }, status: { corpus: 315, 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/business-operations", score: "0.60", }, ], search: "/en/search.json", },};console.log(JSON.stringify(page, null, 2));

# 79 lines · YAML · validated at build# 60 lines · JSON · validated at build# 92 lines · TOML · validated at build# 102 lines · XML · validated at build# 104 lines · Python · read back at build, equals the JSON record# 101 lines · PowerShell · read back at build, equals the JSON record# 114 lines · Go · read back at build, equals the JSON record# 99 lines · JavaScript · read back at build, equals the JSON record · served at /en/insights/powercli-getting-the-usage-of-a-cluster.md

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
Vendors VMware 0.98

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