Open rigofundora opened 1 month ago
Workaround:
As a workaround, I ran the following PS script to call the API directly using the latest API version and it worked.
$sub = "{yourSubscriptionID}"
$rg= "{resourceGroupName}"
$budgetName = "{budgetName}"
$auth=Get-AzAccessToken
$authHeader= $auth.token
$output= Invoke-RestMethod -Uri "https://management.azure.com/subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.Consumption/budgets/$budgetName`?api-version=2023-05-01" -Method DELETE -Headers @{"Authorization"="Bearer $authHeader"}
Alternatively, we can also use Azure CLI command az consumption budget | Microsoft Learn which uses API version 2023-05-01 that supports MCA offers
This is also true for the sister commands.
Get-AzConsumptionBudget Get-AzConsumptionBudget: Operation returned an invalid status code 'UnprocessableEntity'
Get-AzConsumptionBudget -debug
DEBUG: 10:22:26 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 10:22:26 AM - GetAzureRmConsumptionBudget begin processing with ParameterSet '__AllParameterSets'.
DEBUG: 10:22:26 AM - using account id 'aadwimal01@roberthalf.com'...
DEBUG: 10:22:26 AM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: '
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.windows.net//.default
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] Access token is not expired. Returning the found cache entry. [Current time (08/29/2024 17:22:26) - Expiration Time (08/29/2024 18:14:02 +00:00) - Extended Expiration Time (08/29/2024 18:14:02 +00:00)]
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.61.3.0 MSAL.CoreCLR .NET 8.0.1 Microsoft Windows 10.0.22631 [2024-08-29 17:22:26Z - b134e100-5296-45e7-950c-f26eac9c3dc1] AT expiration time: 8/29/2024 6:14:02 PM +00:00, scopes: https://management.core.windows.net//.default https://management.core.windows.net//user_impersonation. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2024-08-29T18:14:02.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '
HTTP Method: GET
Absolute Uri:
https://management.azure.com/subscriptions/
Headers: Accept-Language : en-US x-ms-client-request-id : 7fe7e715-a2ee-44d1-9960-5534697f653a
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code: UnprocessableEntity
Headers: Cache-Control : no-cache Pragma : no-cache session-id : 60c54354-fe2f-40d8-a586-6a9aaf2364d7 x-ms-request-id : 62821d0e-c0d9-4e23-8ea9-7af0b2400e0c x-ms-correlation-request-id : 851d7e24-6745-4e9f-9c99-6b4e0712c5ed x-ms-client-request-id : 7fe7e715-a2ee-44d1-9960-5534697f653a X-Powered-By : ASP.NET x-ms-ratelimit-remaining-subscription-reads: 499 x-ms-ratelimit-remaining-subscription-global-reads: 7499 x-ms-routing-request-id : WESTUS:20240829T172227Z:851d7e24-6745-4e9f-9c99-6b4e0712c5ed Strict-Transport-Security : max-age=31536000; includeSubDomains X-Content-Type-Options : nosniff X-Cache : CONFIG_NOCACHE X-MSEdge-Ref : Ref A: F4BDD7E5A3514BE096EDD6363E4E563C Ref B: SJC211051203035 Ref C: 2024-08-29T17:22:26Z Date : Thu, 29 Aug 2024 17:22:27 GMT
Body: { "error": { "code": "422", "message": "This operation is not supported in the version specified in the request. Please use version 2018-12-01-preview or later. (Request ID: 62821d0e-c0d9-4e23-8ea9-7af0b2400e0c)" } }
DEBUG: 10:22:27 AM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [], Cmdlet = []. Returning default value [False]. Get-AzConsumptionBudget: Operation returned an invalid status code 'UnprocessableEntity' DEBUG: 10:22:27 AM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: 10:22:27 AM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: 10:22:27 AM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: AzureQoSEvent: Module: Az.Billing:2.0.4; CommandName: Get-AzConsumptionBudget; PSVersion: 7.4.1; IsSuccess: False; Duration: 00:00:00.8957602; SanitizeDuration: 00:00:00; Exception: Operation returned an invalid status code 'UnprocessableEntity'; DEBUG: 10:22:27 AM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True]. DEBUG: 10:22:27 AM - GetAzureRmConsumptionBudget end processing.
Description
PS cmdlet Remove-AzConsumptionBudget under the Az.Billing module don’t work for MCA billing scopes. This is due to the cmdlet using an older version of Microsoft Consumption budgets API which don’t support MCA offers. MCA offers are supported on api version 2018-12-01-preview or later. The cmdlet is using api-version=2018-01-31.
Command:
Remove-AzConsumptionBudget -Name "testMCAbudget" -ResourceGroupName "rigo-test-rg" -debug
https://learn.microsoft.com/en-us/powershell/module/az.billing/remove-azconsumptionbudget?view=azps-12.0.0
Issue script & Debug output
Environment data
Module versions
Error output