Try like this
Connect-VIServer"vc.com"
# Get a list of hosts in a specific cluster (omit the get-cluster to get all hosts, and just use get-vmhost)
$hosts=get-cluster"MYCLUSTER"|Get-VMHost
# Define an empty table
$table=@()
# Loop through each host found
foreach($vmhostin$hosts){
# Create an empty row
$row=""|Select-Object Hostname, LogicalCPUs, CPUsAssigned, CPUOvercommited, MemoryGB, MemoryAssignedGB, MemoryOvercomitted
# Add the hostname to the row
$row.Hostname=(($vmhost.name).split("."))[0]
# Add the number of logical CPUs to the row
$row.LogicalCPUs=($vmhost.numcpu|Measure-Object-Sum).Sum
# Get the number of vCPUs assigned
$row.CPUsAssigned=($vmhost|Get-VM|Where-Object{$_.powerstate-eq"poweredon"}|Measure-Object-Property numcpu -Sum).Sum
if($row.CPUsAssigned-eq$null){
$row.CPUsAssigned=0
}
# Get the CPU overcommitment level as a percentage
$perc=[int](($row.CPUsAssigned/$row.LogicalCPUs)*100)
# Warn if CPU overcommitted
if($perc-gt100){
$row.CPUOvercommited="YES - "+$perc+"%"
}
else{
$row.CPUOvercommited="No"
}
# Add the available memory to the row
$row.MemoryGB=[math]::Round(($vmhost.MemoryTotalGB|Measure-Object-Sum).Sum,1)
# Get the memory assigned
$row.MemoryAssignedGB=($vmhost|Get-VM|Where-Object{$_.powerstate-eq"poweredon"}|Measure-Object-Property MemoryGB -Sum).Sum
if($row.MemoryAssignedGB-eq$null){
$row.MemoryAssignedGB=0
}
# Get the memory overcommitment level as a percentage
$perc=[int](($row.MemoryAssignedGB/$row.MemoryGB)*100)
# Warn if memory overcommitted
if($perc-gt100){
$row.MemoryOvercomitted="YES - "+$perc+"%"
}
else{
$row.MemoryOvercomitted="No"
}
# Add the current row to the table
$table=$table+$row
}
# Save the table to CSV
$table|Export-Csv-Path .\report.csv -NoTypeInformation -UseCulture