VMware Cloud Community
Heroh
Contributor
Contributor

Figuring out how to get this kind of format

Hello experts,

Anyone would help me how to script this format and output this to html. Thanks for your help.

Cluster name

ESXi name | CpuUsage | TotalCpu%Util | MemUsage | TotalMem% | Version + update # 

0 Kudos
5 Replies
LucD
Leadership
Leadership

What do you already have?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Heroh
Contributor
Contributor

Hi LucD,

i tried this so far but I could not figure out how to go around with it. thanks

$clusters = get-cluster

foreach($cluster in $clusters){

$esxisvr = get-vmhost | select-object @{n='Cluster'; e={$_.parent}}, @{n='ESXi Host'; e={$_.name}}, cputotalmhz, cpuusagemhz, @{n='TotalCpuUsage(%)'; e={[Math]::Round((($_.cpuusagemhz / $_.cputotalmhz)*100),2)}}, @{n='MemoryTotal(GB)'; e={[Math]::Round($_.MemoryTotalGB,2)}}, @{n='MemoryUsage(GB)'; e={[Math]::Round($_.MemoryUsageGB,2)}}, @{n='TotalMemUsage(%)'; e={[Math]::Round((($_.memoryusagemb / $_.memorytotalmb)*100),2)}}, version, build

write-host "Cluster Name: $cluster`n", $esxi

}

0 Kudos
LucD
Leadership
Leadership

What do you mean with "... I could not figure out how to go around with it"?
The $esxisvr variable contains the properties you selected, but you seem to be printing a variable $esxi, which isn't defined nor populated in that snippet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Heroh
Contributor
Contributor

just a mistype. it should be $esxisvr

with this script i am getting all the VM hosts of the datacenter and not separated on per cluster. i want to separate them per cluster.

0 Kudos
LucD
Leadership
Leadership

Use the pipeline.

Something like this

Get-Cluster -PipelineVariable cluster |
Get-VMHost |
Select-Object @{n='Cluster'; e={$cluster.Name}}, 
    @{n='ESXi Host'; e={$_.name}}, 
    cputotalmhz, cpuusagemhz, 
    @{n='TotalCpuUsage(%)'; e={[Math]::Round((($_.cpuusagemhz / $_.cputotalmhz)*100),2)}}, 
    @{n='MemoryTotal(GB)'; e={[Math]::Round($_.MemoryTotalGB,2)}}, 
    @{n='MemoryUsage(GB)'; e={[Math]::Round($_.MemoryUsageGB,2)}},
    @{n='TotalMemUsage(%)'; e={[Math]::Round((($_.memoryusagemb / $_.memorytotalmb)*100),2)}},
    version, build


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos