Automation

 View Only
  • 1.  Host Statistic - need the format in a particular format

    Posted Sep 15, 2016 03:44 PM

    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



  • 2.  RE: Host Statistic - need the format in a particular format
    Best Answer

    Posted Sep 15, 2016 07:04 PM

    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



  • 3.  RE: Host Statistic - need the format in a particular format

    Posted Sep 16, 2016 03:08 PM

    Thank you LucD,

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

    Again....thanks