Hi @joseph kobti ,
Welcome to Microsoft Q&A Forum, thank you for posting your query here!
To test this successfully, adjust the start and end times according to your requirements and run the process. The detailed step-by-step explanation is provided below.
PowerShell Script below Just change start and end date It will give you cost for each resource.
# Define the start and end dates for December 2024
$startDate = "2025-01-01"
$endDate = "2025-01-22"
# Fetch cost details for the specified date range
$costDetails = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate
# Check for the available cost property
if ($costDetails -and $costDetails[0].PSObject.Properties.Name -contains "CostInBillingCurrency") {
$costProperty = "CostInBillingCurrency"
} elseif ($costDetails[0].PSObject.Properties.Name -contains "PreTaxCost") {
$costProperty = "PreTaxCost"
} else {
Write-Error "Unable to find a cost-related property in the returned data."
return
}
# Calculate the total cost for the month
$totalCost = ($costDetails | Measure-Object -Property $costProperty -Sum).Sum
# Save details to a CSV
$outputFile = "AzureCostDetails_December2024.csv"
$costDetails | Export-Csv -Path $outputFile -NoTypeInformation
# Display results
Write-Host "Total cost for December 2024: $($totalCost.ToString("C"))"
Write-Host "Cost details for December 2024 saved to $outputFile"
Please find the below artifacts of the output: -
$costDetails : Has cost of individual cost of the resources in your subscription
$totalCost contains total cost of the resources
$outputFile = "AzureCostDetails_December2024.csv"
Output will be stored in the AzureCostDetails_December2024.csv which will get downloaded as a csv Open the file you can see the total cost refer to column "PretaxCost Column"
Feel free to reach out if you have any further questions or need additional information—I’m happy to assist!
Please provide your valuable comments
Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.