drivera01
Enthusiast
Enthusiast

Host Statistic - need the format in a particular format

Jump to solution

So I am trying to  do it in this format so I can send the output to HTML.

This is the items I found on the discussion board from LucD that I am trying to use

Get-VMHost -Name MyEsx |

Select Name,

    @{N='CPU GHz Capacity';E={[math]::Round($_.CpuTotalMhz/1000,2)}},

    @{N='CPU GHz Used';E={[math]::Round($_.CpuUsageMhz/1000,2)}},

    @{N='CPU GHz Free';E={[math]::Round(($_.CpuTotalMhz - $_.CpuUsageMhz)/1000,2)}},

    @{N='Memory Capacity GB';E={[math]::Round($_.MemoryTotalGB,2)}},

    @{N='Memory Used GB';E={[math]::Round($_.MemoryUsageGB,2)}},

    @{N='Memory Free GB';E={[math]::Round(($_.MemoryTotalGB - $_.MemoryUsageGB),2)}}

BUT I need a way to populate the lines below with the correct syntax.

My issue is only on the CPU and Mem portions...

foreach ($vmhost in get-vmhost )

{

$reportedhosts= "" | Select-Object Host, "CPU Capacity", "CPU Used"

$reportedhosts.Host = $vmhost.Name

$reportedhosts."CPU Capacity" = $vmhost.{[math]::Round($_.CpuTotalMhz/1000,2)}

$reportedhosts."CPU Used" = $vmhost.{[math]::Round($_.CpuTotalMhz/1000,2)}

I know I can do for instance:

$reportedhosts."CPU Capacity" = $vmhost.CpuTotalMhz 


BUT IT IS NOT ROUNDED.... I WANT IT ROUNDED

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

One option is to use the [Math]::Round method

$reportedhosts."CPU Capacity" = [Math]::Round($vmhost.CpuTotalMhz,1)

Another is the format operator

$reportedhosts."CPU Capacity" = "{0:N1}" -f $vmhost.CpuTotalMhz


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

One option is to use the [Math]::Round method

$reportedhosts."CPU Capacity" = [Math]::Round($vmhost.CpuTotalMhz,1)

Another is the format operator

$reportedhosts."CPU Capacity" = "{0:N1}" -f $vmhost.CpuTotalMhz


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

0 Kudos
drivera01
Enthusiast
Enthusiast

Thank you LucD,

I figured out a solution but your is much better!!! As always.

Again....thanks

0 Kudos