How to Find the Cost of Azure VM’s for a month
Azure VM monthly cost reporting is very important for most of the Azure Admins nowadays and you should know how to get the data from the Azure with the help of PowerShell script. You should use the new Az-Module for this task.
You can find the consumption details of the Azure VM’s with the help of the below script. First, get the consumption details of the whole month for all the resources from Azure with the help of Get-AzConsumptionUsageDetail.
$Octcost=Get-AzConsumptionUsageDetail -StartDate “10-01-2019” -EndDate “10-31-2019”
Now filter the list for Azure VM’s only.
$octvmlist=$octcost | Where-Object{$_.InstanceID -like “*/Microsoft.Compute/virtualMachines/*”}
In next step you can filter the list based on below details.
$Filterlist=$octvmlist | Select-Object -Property UsageDate,ResourceId,InstanceName,ResourceType,ResourceLocation,ResourceGroupName,PreTaxCost,Currency
Once the data is available and stored in a variable you can export it to a CSV file.
$Filterlist | Export-Csv -Path “C:\Azure\Date\MonthlyData\Oct2019.csv”
That’s all for today, I hope this post is going to help you greatly.