I am working on a report to provide totals for all VMs and hosts. The last part I have difficulty figuring out is generating the total of CPUs and memory for all of the templates in a particular cluster.
The code below works to gather the data, I just need generating a total of each and storing that in a variable. I've tried to do so using Measure-Object -Property MemoryMB -sum).sum)) but I get an error regardless of how I use it with the code below.
$clusName1 = "Clustername"
$esx1 = Get-Cluster -Name $clusName1 | Get-VMHost | %{$_.Extensiondata.MoRef}
$templateCPUTotal = Get-Template | select @{N="CPU";E={[Math]::Round(($_.ExtensionData.Config.Hardware.NumCPU))}}
$clusName1 = "Clustername"
$esx1 = Get-Cluster -Name $clusName1 | Get-VMHost | %{$_.Extensiondata.MoRef}
$templateMemoryTotal = Get-Template | select @{N='Memory';E={[Math]::Round(($_.ExtensionData.Config.Hardware.MemoryMB)/1024,1)}}
Try something like this
Get-Template |
Select Name,
@{N='CPU';E={[Math]::Round(($_.ExtensionData.Config.Hardware.NumCPU))}},
@{N='Memory';E={[Math]::Round(($_.ExtensionData.Config.Hardware.MemoryMB)/1024,1)}}
$report += ('' | Select @{N='Name';E={'Totals'}},
@{N='CPU';E={($report | Measure-Object -Property CPU -Sum).Sum}},
@{N='Memory';E={($report | Measure-Object -Property Memory -Sum).Sum}})
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-Template |
Select Name,
@{N='CPU';E={[Math]::Round(($_.ExtensionData.Config.Hardware.NumCPU))}},
@{N='Memory';E={[Math]::Round(($_.ExtensionData.Config.Hardware.MemoryMB)/1024,1)}}
$report += ('' | Select @{N='Name';E={'Totals'}},
@{N='CPU';E={($report | Measure-Object -Property CPU -Sum).Sum}},
@{N='Memory';E={($report | Measure-Object -Property Memory -Sum).Sum}})
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked great!
Thanks LucD!