Rob and Vinay,
I haven't worked on this topic since then, but the last thing that I had got working is to configure and run an export through the REST API. See the PowerShell code below. Replace the '<>' placeholders for for subscription ID, access token and storage account name
### Cost management contributor at the scope where the export is required to be configured.
### Storage account contributor on the storage account.
################ Create an export ###########################
$Url = "https://management.azure.com/subscriptions/<subscription ID>/providers/Microsoft.CostManagement/exports/exportwithapi?api-version=2021-10-01"
$body = @'
{
"properties": {
"definition": {
"dataset": {
"granularity": "Daily",
"grouping": []
},
"timePeriod": {
"from": "2024-12-01T00:00:00.000Z",
"to": "2024-12-30T00:00:00.000Z"
},
"timeframe": "Custom",
"type": "Usage"
},
"deliveryInfo": {
"destination": {
"container": "cost",
"rootFolderPath": "apicostexport",
"resourceId": "/subscriptions/<subscription ID>/resourceGroups/Test/providers/Microsoft.Storage/storageAccounts/<stg-account-name>"
}
},
"format": "Csv",
"partitionData": false
}
}
'@
$token = "<access token>"
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = 'application/json'
}
Invoke-RestMethod -Method Put -Uri $url -Body $body -Headers $headers
################ Run the export ###########################
$Url = "https://management.azure.com/subscriptions/<subscription ID>/providers/Microsoft.CostManagement/exports/exportwithapi/run?api-version=2021-10-01"
$body = @'
{
"properties": {
"definition": {
"dataset": {
"granularity": "Daily",
"grouping": []
},
"timePeriod": {
"from": "2022-12-01T00:00:00.000Z",
"to": "2022-12-30T00:00:00.000Z"
},
"timeframe": "Custom",
"type": "Usage"
},
"deliveryInfo": {
"destination": {
"container": "cost",
"rootFolderPath": "apicostexport",
"resourceId": "/subscriptions/<subscription ID>/resourceGroups/Test/providers/Microsoft.Storage/storageAccounts/<stg-account-name>"
}
},
"format": "Csv",
"partitionData": false
}
}
'@
$token = "<token>"
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = 'application/json'
}
Invoke-RestMethod -Method POST -Uri $url -Body $body -Headers $headers