Hello!
am trying to modifying below script to give me the number of hosts and vms in the cluster along with the usage metrics.
Connect-VIServer -Server XXX -User domain\xx -Password xxx
$report = @()
$Date=Get-Date
$clusterName = "*"
foreach($cluster in Get-Cluster -Name $clusterName){
$esx = $cluster | Get-VMHost
$ds = Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS" -and $_.Extensiondata.Summary.MultipleHostAccess}
$vms=Get-Cluster | Select @{N="VM Count"; E={($_ | Get-VM).Count}}
$hosts=Get-Cluster | Select Name, @{N="Host Count"; E={($_ | Get-VMHost).Count}}
$statcpu = Get-Stat -Entity ($esx)-start 03/22/2020 -Finish 04/04/2020 -MaxSamples 10000 -stat cpu.usage.average
$cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
$statmem = Get-Stat -Entity ($esx)-start 03/22/2020 -Finish 04/04/2020 -MaxSamples 10000 -stat mem.usage.average
$mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
$row = "" | Select VCname,DCname,Clustername,"Total Physical Memory (GB)",
"Configured Memory GB","Available Memroy (GB)",
"Total CPU (Mhz)","Configured CPU (Mhz)",
"Available CPU (Mhz)","Total Disk Space (GB)",
"Configured Disk Space (GB)","Available Disk Space (GB)","Total Disk Space (TB)",
"Configured Disk Space (TB)","Available Disk Space (TB)","CPUCount","CPUAverage","CPUMax","CPUMin","MemoryAverage","MemoryMax","MemoryMin","VMCount"
$row.VCname = $cluster.Uid.Split(':@')[1]
$row.DCname = (Get-Datacenter -Cluster $cluster).Name
$row.Clustername = $cluster.Name
$row."Total Physical Memory (GB)" = ($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum
$row."Configured Memory GB" = ($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum
$row."Available Memroy (GB)" = ($esx | Measure-Object -InputObject {$_.MemoryTotalGB - $_.MemoryUsageGB} -Sum).Sum
$row."Total CPU (Mhz)" = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
$row."Configured CPU (Mhz)" = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
$row."Available CPU (Mhz)" = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum
$row."Total Disk Space (GB)" = ($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityGB -Sum).Sum
$row."Configured Disk Space (GB)" = ($ds | Measure-Object -InputObject {$_.CapacityGB - $_.FreeSpaceGB} -Sum).Sum
$row."Available Disk Space (GB)" = ($ds | Measure-Object -Property FreeSpaceGB -Sum).Sum
$row."Total Disk Space (TB)" = ((($ds | where {$_.Type -eq "VMFS"} | Measure-Object -Property CapacityGB -Sum).Sum)/ (1024))
$row."Configured Disk Space (TB)" = ((($ds | Measure-Object -InputObject {$_.CapacityGB - $_.FreeSpaceGB} -Sum).Sum)/ (1024))
$row."Available Disk Space (TB)" = ((($ds | Measure-Object -Property FreeSpaceGB -Sum).Sum) / (1024))
$row."CPUCount" = $cpu.count
$row."CPUAverage" = $cpu.Average
$row."CPUMax" = $cpu.Maximum
$row."CPUMin" = $cpu.Minimum
$row."MemoryAverage" = $mem.Average
$row."MemoryMax" = $mem.Maximum
$row."MemoryMin" = $mem.Minimum
$row.VMCount = $vms
$row.hostcount=$hosts
$report += $row
}
$report | Export-Csv "C:\temp\xx.csv" -NoTypeInformation -UseCulture
below is the output, vmcount and host count showing as system.object.
![]()