Azure / Azure/azure-powershell
PS cmdlet Remove-AzConsumptionBudget under the Az.Billing module don’t support MCA billing scopes due to the API version used.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### 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
```PowerShell
PS C:\Users\rigobertof> Remove-AzConsumptionBudget -Name "testMCAbudget" -ResourceGroupName "rigo-test-rg" -debug
DEBUG: 6:20:22 PM - RemoveAzureRmConsumptionBudget begin processing with ParameterSet 'Subscription'.
DEBUG: 6:20:22 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove Consumption Budget" on target "testMCAbudget".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
DEBUG: [Common.Authentication]: Authenticating using Account:, environment: 'AzureCloud', tenant:
DEBUG: 6:20:25 PM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 6:20:25 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/',
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - b01f3202-f570-4860-b340-f8bf57ed6457] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z] Found 2 cache accounts and 0 broker accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z] Returning 2 accounts
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] MSAL MSAL.CoreCLR with assembly version '4.56.0.0'. CorrelationId(f7747a65-877e-469c-b245-2fefd37c69ee)
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] LoginHint provided: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] Account provided: True
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] ForceRefresh: False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - f7747a65-877e-469c-b245-2fefd37c69ee
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.windows.net//.default
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] Access token is not expired. Returning the found cache entry. [Current time (07/23/2024 00:20:25) - Expiration Time (07/23/2024 01:15:07 +00:00) - Extended Expiration Time (07/23/2024 01:15:07 +00:00)]
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.56.0.0 MSAL.CoreCLR .NET 8.0.4 Microsoft Windows 10.0.22631 [2024-07-23 00:20:25Z - f7747a65-877e-469c-b245-2fefd37c69ee] AT expiration time: 7/23/2024 1:15:07 AM +00:00, scopes: https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2024-07-23T01:15:07.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: , UserId:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
DELETE
Absolute Uri:
https://management.azure.com/subscriptions/{sub_ID}/resourceGroups/rigo-test-rg/providers/Microsoft.Consumption/budgets/testMCAbudget?api-version=2018-01-31
Headers:
Accept-Language : en-US
x-ms-client-request-id : 1971b517-8231-4365-96b2-57839422f487
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
UnprocessableEntity
Headers:
Cache-Control : no-cache
Pragma : no-cache
session-id : eeeadc0b-b296-433f-9464-4c80940c9f40
x-ms-request-id : 88aae6ab-3a14-4033-891c-d53b83c9f333
x-ms-correlation-request-id : 12fcd818-1ca7-49ea-b4d8-35e1611bd89d
x-ms-client-request-id : 1971b517-8231-4365-96b2-57839422f487
X-Powered-By : ASP.NET
x-ms-ratelimit-remaining-subscription-deletes: 199
x-ms-ratelimit-remaining-subscription-global-deletes: 2999
x-ms-routing-request-id : EASTUS2:20240723T002028Z:12fcd818-1ca7-49ea-b4d8-35e1611bd89d
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
X-Cache : CONFIG_NOCACHE
X-MSEdge-Ref : Ref A: 3C5C1A76F47047D98BCDA11CB79F587B Ref B: BN1AA2051014029 Ref C: 2024-07-23T00:20:27Z
Date : Tue, 23 Jul 2024 00:20: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: 88aae6ab-3a14-4033-891c-d53b83c9f333)"
}
}
DEBUG: 6:20:27 PM - [ConfigManager] Got nothing from [DisableErrorRecordsPersistence], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 6:20:27 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
Remove-AzConsumptionBudget: Operation returned an invalid status code 'UnprocessableEntity'
DEBUG: 6:20:27 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 6:20:27 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 6:20:27 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Billing:2.0.3; CommandName: Remove-AzConsumptionBudget; PSVersion: 7.4.2; IsSuccess: False; Duration: 00:00:04.2999590; Exception: Operation returned an invalid status code 'UnprocessableEntity';
DEBUG: 6:20:27 PM - RemoveAzureRmConsumptionBudget end processing.
```
### Environment data
```PowerShell
PS C:\Users\rigof> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
PS C:\Users\rigof> Get-Module Az*
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.15.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 2.0.3 Az.Billing {Get-AzBillingAccount, Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzBillingProfile…}
```
### Error output
```PowerShell
HistoryId: 1
Message : Operation returned an invalid status code 'UnprocessableEntity'
StackTrace : at Microsoft.Azure.Management.Consumption.BudgetsOperations.DeleteByResourceGroupNameWithHttpMessagesAsync(String resourceGroupName, String budgetName, Dictionary`2 customHeaders, CancellationToken
cancellationToken)
at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.DeleteByResourceGroupNameAsync(IBudgetsOperations operations, String resourceGroupName, String budgetName, CancellationToken
cancellationToken)
at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.DeleteByResourceGroupName(IBudgetsOperations operations, String resourceGroupName, String budgetName)
at Microsoft.Azure.Commands.Consumption.Cmdlets.Budget.RemoveAzureRmConsumptionBudget.ExecuteCmdlet()
Exception : Microsoft.Azure.Management.Consumption.Models.ErrorResponseException
InvocationInfo : {Remove-AzConsumptionBudget}
Line : Remove-AzConsumptionBudget -Name "testMCAbudget" -ResourceGroupName "rigo-test-rg"
Position : At line:1 char:1
+ Remove-AzConsumptionBudget -Name "testMCAbudget" -ResourceGroupName …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 1
```
Contributor guide
Assessment
This issue has not been assessed yet.