PowerCLI

 View Only
  • 1.  Get-Stat ESXI and get average per day

    Posted Mar 28, 2019 10:51 AM

    Hi for all!

    Very simple script:

    $entities = Get-VMHost esx-01

    $stat = "cpu.usage.average"

    $start = (Get-Date).AddDays(-4)

    Get-Stat -Entity $entities -Stat $stat -Start $start  |

    Select @{N='ESXi';E={$_.Entity.Name}},Timestamp,Value |

    Sort-Object -Property Timestamp

    Works fine, but I get a lot of value.

    What needs to be added to the script to get 4 lines, with average values per day?



  • 2.  RE: Get-Stat ESXI and get average per day
    Best Answer

    Posted Mar 28, 2019 11:15 AM

    Try something like this.
    Btw I have done a post on the concept, see PowerCLI & VSphere Statistics – Part 2 – Come Together

    $entities = Get-VMHost esx-01 

    $stat = "cpu.usage.average"

    $start = (Get-Date).AddDays(-4)

    Get-Stat -Entity $entities -Stat $stat -Start $start -Instance '' |

       Sort-Object -Property Timestamp |

       Group-Object -Property { $_.Timestamp.DayOfYear } |

       ForEach-Object -Process {

       New-Object PSOBject -Property ([ordered]@{

       ESXi = $_.Group[0].Entity.Name

       Date = $_.Group[0].Timestamp.ToString('yyyyMMdd')

       CpuUsageAvg = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 1)

       })

    }



  • 3.  RE: Get-Stat ESXI and get average per day

    Posted Mar 28, 2019 12:22 PM

    Thanks LUCD!

    amazing!

    thanks for the article, I read