Hello Vinoth Kaliaperumal
Welcome to Microsoft Q&A Platform, thanks for posting your query here.
For your ask "I need to pull CPU usage report of all the virtual machines present in a subscription."
As mentioned in previous response, there is not straight way from Azure Portal.
You can do this using scripting. I just tried this using a powershell script and it works. Please note that this is a sample script and you may need to add/modify based on your need.
#get all vms in a subscription
$vms = Get-AzVM
#get the last 3 days data
#end date
$et=Get-Date
#start date
$st=$et.AddDays(-3)
$arr =@()
foreach($vm in $vms)
{
$s = ""
#percentage cpu usage
$cpu = Get-AzMetric -ResourceId $vm.Id -MetricName "Percentage CPU" -DetailedOutput -StartTime $st `
-EndTime $et -TimeGrain 12:00:00 -WarningAction SilentlyContinue
# 3 days == 72hours == 12*6hours
$cpu_total=0.0
foreach($c in $cpu.Data.Average)
{
#this is a average value for 12 hours, so total = $c*12 (or should be $c*12*60*60)
$cpu_total += $c*12
}
# add all the related info to the string
$s = "VM Name: " + $vm.name + "; Resource Group: " + $vm.ResourceGroupName + "; CPU: " +$cpu_total
# add the above string to an array
$arr += $s
}
#check the values in the array
$arr
Output sample for your reference:
Hope this helps.
If the suggested response helped you resolve your issue, please 'Accept as answer', so that it can help others in the community looking for help on similar topics.