Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connect-AzAccount
- $vms = Get-AzVm
- $Report = @()
- foreach ($vm in $vms) {
- $rid = $vm.id
- $cpu = Get-AzMetric -ResourceId $rid -TimeGrain 00:15:00 -StartTime 2019-09-22T12:00:00Z -EndTime 2019-09-28T23:59:59Z -WarningAction silentlyContinue
- $curAvg = 0
- $max = 0
- $n = 1
- foreach ($c in $cpu.data){
- if($c.average -gt $max){
- $max = $c.average
- }
- if($c.average -gt 0){
- $curAvg = $curAvg + ($c.average - $curAvg)/$n
- $n = $n + 1
- }
- }
- $Object = New-Object System.Object
- $Object | Add-Member -type NoteProperty -name "Id" -Value $rid
- $Object | Add-Member -type NoteProperty -name "AveCpu" -Value $curAvg
- $Object | Add-Member -type NoteProperty -name "MaxCpu" -Value $max
- $Object | Add-Member -type NoteProperty -name "Count" -Value $n
- if($curAvg -gt 0){
- $Report += $Object
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement