Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Connect-AzAccount
  2.  
  3. $vms = Get-AzVm
  4.  
  5. $Report = @()
  6. foreach ($vm in $vms) {
  7.  
  8. $rid = $vm.id
  9.  
  10. $cpu = Get-AzMetric -ResourceId $rid -TimeGrain 00:15:00 -StartTime 2019-09-22T12:00:00Z -EndTime 2019-09-28T23:59:59Z -WarningAction silentlyContinue
  11.  
  12. $curAvg = 0
  13. $max = 0
  14. $n = 1
  15.  
  16. foreach ($c in $cpu.data){
  17.  
  18. if($c.average -gt $max){
  19. $max = $c.average
  20. }
  21.  
  22. if($c.average -gt 0){
  23.  
  24. $curAvg = $curAvg + ($c.average - $curAvg)/$n
  25. $n = $n + 1
  26. }
  27. }
  28.  
  29. $Object = New-Object System.Object
  30. $Object | Add-Member -type NoteProperty -name "Id" -Value $rid
  31. $Object | Add-Member -type NoteProperty -name "AveCpu" -Value $curAvg
  32. $Object | Add-Member -type NoteProperty -name "MaxCpu" -Value $max
  33. $Object | Add-Member -type NoteProperty -name "Count" -Value $n
  34.  
  35. if($curAvg -gt 0){
  36. $Report += $Object
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement