Ok, I think I got it.
The first script will store the values in a CSV file and will capture the data for a specific time interval
$esxImpl = Get-VMHost <ESX-hostname>
$esx = $esxImpl | Get-View
$cpuMHz = ($esx.Hardware.CpuInfo.Hz * $esx.Hardware.CpuInfo.NumCpuCores)/1Mb
$memMb = $esx.Hardware.MemorySize /1Mb
$stats = Get-Stat -Entity $esxImpl -Stat cpu.usagemhz.average,mem.consumed.average -Start (Get-Date).addhours(-1) -IntervalMins 5
$gstats = $stats | Group-Object -Property Timestamp
$report = @()
foreach($entry in $gstats){
$row = "" | select ESXHostName, Timestamp, TotalCPUMHz, UsedCPUMHz, AvailCPUMHz, TotalMemMb, UsedMemMb, AvailMemMb
$row.ESXHostName = $esx.Name
$row.Timestamp = $entry.Values[0]
$row.TotalCPUMHz = "{0:N2}" -f $cpuMHz
$row.UsedCPUMHz = "{0:N2}" -f ($entry.Group[0].Value)
$row.AvailCPUMhz = "{0:N2}" -f ([float]$row.TotalCPUMHz - [float]$row.UsedCPUMHz)
$row.TotalMemMb = "{0:N2}" -f $memMb
$row.UsedMemMb = "{0:N2}" -f ($entry.Group[1].Value / 1Kb)
$row.AvailMemMb = "{0:N2}" -f ([float]$row.TotalMemMb - [float]$row.UsedMemMb)
$report += $row
}
$report | Export-Csv "C:\Stats.csv" -NoTypeInformation
If you want just 1 line of output with the current values use this script
$esxImpl = Get-VMHost <ESX-hostname>
$esx = $esxImpl | Get-View
$cpuMHz = ($esx.Hardware.CpuInfo.Hz * $esx.Hardware.CpuInfo.NumCpuCores)/1Mb
$memMb = $esx.Hardware.MemorySize /1Mb
$stats = Get-Stat -Entity $esxImpl -Stat cpu.usagemhz.average,mem.consumed.average -MaxSamples 1
$gstats = $stats | Group-Object -Property Timestamp
$report = @()
foreach($entry in $gstats){
$row = "" | select ESXHostName, Timestamp, TotalCPUMHz, UsedCPUMHz, AvailCPUMHz, TotalMemMb, UsedMemMb, AvailMemMb
$row.ESXHostName = $esx.Name
$row.Timestamp = $entry.Values[0]
$row.TotalCPUMHz = "{0:N2}" -f $cpuMHz
$row.UsedCPUMHz = "{0:N2}" -f ($entry.Group[0].Value)
$row.AvailCPUMhz = "{0:N2}" -f ([float]$row.TotalCPUMHz - [float]$row.UsedCPUMHz)
$row.TotalMemMb = "{0:N2}" -f $memMb
$row.UsedMemMb = "{0:N2}" -f ($entry.Group[1].Value / 1Kb)
$row.AvailMemMb = "{0:N2}" -f ([float]$row.TotalMemMb - [float]$row.UsedMemMb)
$report += $row
}
$report | ft