1 2 Previous Next 17 Replies Latest reply on Aug 13, 2019 7:02 AM by wfrancoti Go to original post
      • 15. Re: Script to get VM Maximum CPU and Memory
        wfrancoti Novice

        Hi LucD, sorry to bother you again. I am working on the report generated by your script and I see that the columns PeakCpuMhz are reporting in % instead of Mhz, I checked all the lines and I could not identify why.

         

        StartInterval              EndInterval    MaxCpuTimestamp    PeakCpuMhz

        07/05/2019 12:32    07/08/2019 12:32    22/05/2019 21:00    90,1

        07/05/2019 12:32    07/08/2019 12:32    30/05/2019 21:00    24,4

        07/05/2019 12:32    07/08/2019 12:32    15/05/2019 21:00    23,4

        07/05/2019 12:32    07/08/2019 12:32    17/06/2019 21:00    24,8

        07/05/2019 12:32    07/08/2019 12:32    15/06/2019 21:00    59,4

         

        Can you help me?

         

        Thanks.

         

        $now = Get-Date
        $start = $now.AddMonths(-3)
        $stat = 'cpu.usage.average', 'mem.usage.average'
        $vms = Get-VM | where { $_.ExtensionData.Config.GuestFullName -match "Windows Server 2008" }
        Get-Stat -Entity $vms -Stat $stat -Start $start -Instance '*' -ErrorAction SilentlyContinue |
        Group-Object -Property { $_.Entity.Name } |
        ForEach-Object -Process {
           $maxCpu = $_.Group | where { $_.MetricId -eq 'cpu.usage.average' } |
           Sort-Object -Property value -Descending | select -first 1
           $maxMem = $_.Group | where { $_.MetricId -eq 'mem.usage.average' } |
           Sort-Object -Property value -Descending | select -first 1
           New-Object PSObject -Property ([ordered]@{
           Datacenter = (Get-Datacenter -VM $_.Name).Name
           Cluster = (Get-Cluster -VM $_.Name).Name
           VM = $_.Name
           StartInterval = $start
           EndInterval = $now
           MaxCpuTimestamp = $maxCpu.Timestamp
           PeakCpuMhz = [math]::Round($maxCpu.Value, 1)
           MaxMemTimestamp = $maxMem.Timestamp
           PeakMemGB = [math]::Round($maxMem.Entity.MemoryGB * $maxMem.Value / 100, 1)
           })
        }|
        Export-Csv -Path C:\Users\xxxxxx\Documents\report.csv -NoTypeInformation -UseCulture

           

        PeakCpuMhzMaxMemTimestampPeakMemGB
        • 16. Re: Script to get VM Maximum CPU and Memory
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          Indeed, we have to change the metric to get the CPU usage in Mhz.

           

          $now = Get-Date

          $start = $now.AddMonths(-3)

          $stat = 'cpu.usagemhz.average', 'mem.usage.average'

          $vms = Get-VM | where { $_.ExtensionData.Config.GuestFullName -match "Windows Server 2008" }

          Get-Stat -Entity $vms -Stat $stat -Start $start -Instance '*' -ErrorAction SilentlyContinue |

          Group-Object -Property { $_.Entity.Name } |

          ForEach-Object -Process {

             $maxCpu = $_.Group | where { $_.MetricId -eq 'cpu.usagemhz.average' } |

             Sort-Object -Property value -Descending | select -first 1

             $maxMem = $_.Group | where { $_.MetricId -eq 'mem.usage.average' } |

             Sort-Object -Property value -Descending | select -first 1

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

             Datacenter = (Get-Datacenter -VM $_.Name).Name

             Cluster = (Get-Cluster -VM $_.Name).Name

             VM = $_.Name

             StartInterval = $start

             EndInterval = $now

             MaxCpuTimestamp = $maxCpu.Timestamp

             PeakCpuMhz = [math]::Round($maxCpu.Value, 1)

             MaxMemTimestamp = $maxMem.Timestamp

             PeakMemGB = [math]::Round($maxMem.Entity.MemoryGB * $maxMem.Value / 100, 1)

             })

          } |

          Export-Csv -Path C:\Users\xxxxxx\Documents\report.csv -NoTypeInformation -UseCulture

          • 17. Re: Script to get VM Maximum CPU and Memory
            wfrancoti Novice

            Thanks again!!!

            1 2 Previous Next