azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzConsumptionBudget : Operation returned an invalid status code 'Unauthorized'

Open DapiCloud opened this issue 7 years ago • 20 comments

Description

Unable to create new budget via Az.Billing.New-AzConsumptionBudget. Error returns in both local PowerShell and in Automation Runbook.

I am able to create budgets in Azure Portal with no problem.

I am able to run Get-AzConsumptionBudget under same context and I get the expected results.

Steps to reproduce

# #Budget details
$name = "test_budget"
$resourceGroup = "AppGateway-RG"
$amount = 50.00
$emails = "[email protected]", "[email protected]"
$contactGroups = "CldSvcs"
$startDate = "2019-08-01"
$endDate = "2019-12-31"

New-AzConsumptionBudget `
   -Name $name `
   -Amount $amount `
   -Category "Cost" `
   -TimeGrain "Annually" `
   -StartDate $startDate `
   -EndDate $endDate `
   -NotificationKey "90 % Usage" `
   -NotificationEnabled `
   -NotificationThreshold 90 `
   -ContactEmail $emails `
   -ContactGroup $contactGroups

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

Script     1.6.1      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}
Script     1.5.1      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}
Script     1.0.0      Az.Advisor                          {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Disable-AzAdvisorRecommendation, Get-AzAdvisorConfiguration...}
Script     1.0.1      Az.Aks                              {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential...}
Script     1.1.0      Az.AnalysisServices                 {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzAnalysisService...
Script     1.2.0      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion, Add-AzApiManagementUserToG...
Script     1.1.0      Az.ApiManagement                    {Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion, Add-AzApiManagementUserToG...
Script     1.0.0      Az.ApiManagement                    {Add-AzApiManagementRegion, Get-AzApiManagementSsoToken, New-AzApiManagementCustomHostnameConfiguration, New-AzApiManageme...
Script     1.0.1      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Set-AzApplicationInsightsPricingPlan...}
Script     1.0.0      Az.ApplicationInsights              {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, Set-AzApplicationInsightsPricingPlan...}
Script     1.3.1      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutoma...
Script     1.2.2      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutoma...
Script     1.2.1      Az.Automation                       {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutomationJobOutputRecord, Import-AzAutoma...
Script     1.1.0      Az.Batch                            {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKey, New-AzBatchAccount...}
Script     1.0.0      Az.Billing                          {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}
Script     1.3.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}
Script     1.2.0      Az.Cdn                              {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile...}
Script     1.2.0      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-AzCognitiveServ...
Script     1.1.1      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-AzCognitiveServ...
Script     1.1.0      Az.CognitiveServices                {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-AzCognitiveServ...
Script     2.4.1      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}
Script     2.1.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}
Script     1.8.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvailabilitySet...}
Script     1.0.1      Az.ContainerInstance                {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerInstanceLog}
Script     1.1.0      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}
Script     1.0.1      Az.ContainerRegistry                {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-AzContainerRegistry...}
Script     1.1.3      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}
Script     1.1.1      Az.DataFactory                      {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactoryV2...}
Script     1.0.0      Az.DataLakeAnalytics                {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCatalogCredential,...
Script     1.2.1      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, Set-Az...
Script     1.2.0      Az.DataLakeStore                    {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, Set-Az...
Script     1.0.0      Az.DeploymentManager                {Get-AzDeploymentManagerArtifactSource, New-AzDeploymentManagerArtifactSource, Set-AzDeploymentManagerArtifactSource, Remo...
Script     1.0.0      Az.DevTestLabs                      {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPolicy...}
Script     1.1.1      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}
Script     1.1.0      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}
Script     1.0.0      Az.Dns                              {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}
Script     1.2.1      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}
Script     1.1.1      Az.EventGrid                        {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}
Script     1.3.0      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}
Script     1.1.0      Az.EventHub                         {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzEventHubNamespace...}
Script     1.1.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor...}
Script     1.0.0      Az.FrontDoor                        {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor...}
Script     2.0.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapReduceJobDefinitio...
Script     1.1.0      Az.HDInsight                        {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDInsightStreamingMapReduceJobDefinitio...
Script     1.2.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}
Script     1.1.0      Az.IotHub                           {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}
Script     1.3.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOp...
Script     1.2.0      Az.KeyVault                         {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOperation, Get-AzKeyVaultCertificateOp...
Script     1.3.0      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfiguration, Get-AzIn...
Script     1.2.1      Az.LogicApp                         {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAccountBatchConfiguration, Get-AzIn...
Script     1.1.0      Az.MachineLearning                  {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-AzMlCommitmentP...
Script     1.0.0      Az.ManagedServices                  {Get-AzManagedServicesAssignment, New-AzManagedServicesAssignment, Remove-AzManagedServicesAssignment, Get-AzManagedServic...
Script     1.0.0      Az.MarketplaceOrdering              {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.1.0      Az.Media                            {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get-AzMediaServiceKey, Get-AzMediaServiceNameAvailability...}
Script     1.2.1      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}
Script     1.1.0      Az.Monitor                          {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile...}
Script     1.12.0     Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGa...
Script     1.8.1      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGa...
Script     1.7.0      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthenticationCertificate, New-AzApplicationGa...
Script     1.1.0      Az.NotificationHubs                 {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRule, Get-AzNotificationHubListKey, Get-AzNotificationHubPNSCred...
Script     1.3.2      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperationalI...
Script     1.2.0      Az.OperationalInsights              {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperationalI...
Script     1.1.2      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}
Script     1.1.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}
Script     1.0.0      Az.PolicyInsights                   {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}
Script     1.1.0      Az.PowerBIEmbedded                  {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollectionAccessKey, Get-AzP...
Script     1.4.3      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecover...
Script     1.4.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecover...
Script     1.3.0      Az.RecoveryServices                 {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServicesVaultSettingsFile, New-AzRecover...
Script     1.1.0      Az.RedisCache                       {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatchSchedule, New-AzRedisCachePatchSche...
Script     1.0.1      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}
Script     1.0.0      Az.Relay                            {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNamespace...}
Script     1.6.1      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}
Script     1.4.0      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}
Script     1.3.1      Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAssignment...}
Script     1.3.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}
Script     1.1.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}
Script     1.0.0      Az.ServiceBus                       {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remove-AzServiceBusNamespace...}
Script     1.1.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, A...
Script     1.0.1      Az.ServiceFabric                    {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-AzServiceFabricClusterCertificate, A...
Script     1.0.2      Az.SignalR                          {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}
Script     1.13.1     Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTranspar...
Script     1.10.0     Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTranspar...
Script     1.9.0      Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTranspar...
Script     1.5.1      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}
Script     1.3.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}
Script     1.2.0      Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAccountKey...}
Script     1.2.0      Az.StorageSync                      {Invoke-AzStorageSyncCompatibilityCheck, New-AzStorageSyncService, Get-AzStorageSyncService, Remove-AzStorageSyncService...}
Script     1.0.0      Az.StreamAnalytics                  {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-AzStreamAnalyticsFunction, Remove-AzSt...
Script     1.0.1      Az.TrafficManager                   {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficManagerCustomHe...
Script     1.4.0      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}
Script     1.2.1      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}
Script     1.2.0      Az.Websites                         {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppServicePlan...}
Binary     2.0.2.16   AzureAD                             {Add-AzureADApplicationOwner, Get-AzureADApplication, Get-AzureADApplicationExtensionProperty, Get-AzureADApplicationOwner...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

Debug output

DEBUG: 11:08:36 AM - NewAzureRmConsumptionBudget begin processing with ParameterSet 'Notification'.
DEBUG: 11:08:36 AM - using account id '[email protected]'...
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud', tenant: '325b4494-1587-40d5-bb31-8b660b7f1038'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '325b4494-1587-40d5-bb31-8b660b7f1038', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/325b4494-1587-40d5-bb31-8b660b7f1038/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: '325b4494-1587-40d5-bb31-8b660b7f1038', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: ADAL PCL.Desktop with assembly version '3.19.2.6005', file version '3.19.50302.0130' and informational version '2a8bec6c4c76d0c1ef819b55bdc3cda2d2605056' is running...

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: === Token Acquisition started: 
        CacheType: null
        Authentication Target: User
        , Authority Host: login.microsoftonline.com

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: === Token Acquisition started:
        Authority: https://login.microsoftonline.com/325b4494-1587-40d5-bb31-8b660b7f1038/
        Resource: https://management.core.windows.net/
        ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
        CacheType: null
        Authentication Target: User
        

DEBUG: [ADAL]: Verbose: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Verbose: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: Loading from cache.

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: 00000000-0000-0000-0000-000000000000 - LoggerBase.cs: Deserialized 2 items to token cache.

DEBUG: [ADAL]: Verbose: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Verbose: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: Looking up cache for a token...

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: An item matching the requested resource was found in the cache

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: An item matching the requested resource was found in the cache

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: 25.8814902866667 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: 25.8814902866667 minutes left until token in cache expires

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: A matching item (access token or refresh token or both) was found in the cache

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 13/08/2019 3:34:29 PM +00:00

DEBUG: [ADAL]: Information: 2019-08-13T15:08:36.5585828Z: e2f94e58-b75b-4216-b99f-9ee5eac2c32d - LoggerBase.cs: === Token Acquisition finished successfully. An access token was returned: Expiration Time: 13/08/2019 3:34:29 PM +00:00Access Token Hash: BnXGWJXSeANfWJ84ovsXNg6xMLS+jZ90bRVgBCa/Q4I=
         User id: a9cf06a7-81da-443b-badb-dd1699e2a34b

DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '08/13/2019 15:34:29 +00:00', MultipleResource? 'True', Tenant: '325b4494-1587-40d5-bb31-8b660b7f1038', UserId: '[email protected]'
DEBUG: [Common.Authentication]: User info for token DisplayId: '[email protected]', Name:  , IdProvider: 'https://sts.windows.net/325b4494-1587-40d5-bb31-8b660b7f1038/', Uid: 'a9cf06a7-81da-443b-badb-dd1699e2a34b'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '08/13/2019 15:34:29 +00:00' Comparing to '08/13/2019 15:08:36 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:25:52.8884171'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/7a0446b1-af1a-4ec8-84c4-879511cda896/providers/Microsoft.Consumption/budgets/test_budget?api-version=2018-01-31

Headers:
x-ms-client-request-id        : a8c61820-6157-41a1-863e-b035faf66ff4
accept-language               : en-US

Body:
{
  "properties": {
    "category": "Cost",
    "amount": 50.0,
    "timeGrain": "Annually",
    "timePeriod": {
      "startDate": "2019-08-01T00:00:00Z",
      "endDate": "2019-12-31T00:00:00Z"
    },
    "filters": {},
    "notifications": {
      "90 % Usage": {
        "enabled": true,
        "operator": "GreaterThanOrEqualTo",
        "threshold": 90.0,
        "contactEmails": [
          "[email protected]",
          "[email protected]"
        ],
        "contactGroups": [
          "DAPI-CldSvcs"
        ]
      }
    }
  }
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
Unauthorized

Headers:
Pragma                        : no-cache
Connection                    : Keep-Alive
session-id                    : a9e874b4-c036-473d-a29e-5bd02dea20b7
Proxy-Support                 : Session-Based-Authentication
x-ms-request-id               : eebc54a5-52d1-412a-8632-fad5f3451077
X-Content-Type-Options        : nosniff
x-ms-routing-request-id       : NORTHCENTRALUS:20190813T150838Z:698e952c-ef80-40b1-a470-8678ed7d2a79
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin   : *
x-ms-correlation-request-id   : 698e952c-ef80-40b1-a470-8678ed7d2a79
x-ms-ratelimit-remaining-subscription-writes: 1199
Cache-Control                 : no-cache
Date                          : Tue, 13 Aug 2019 15:08:37 GMT
Via                           : 1.1 10.251.133.56 (McAfee Web Gateway 7.8.2.6.0.27882)
WWW-Authenticate              : Bearer

Body:
{
  "error": {
    "code": "401",
    "message": "Unauthorized. Request ID: eebc54a5-52d1-412a-8632-fad5f3451077"
  }
}


New-AzConsumptionBudget : Operation returned an invalid status code 'Unauthorized'
At D:\MyCloudProjects\CloudTeam\Scripts\Azure Code\Automation\Costing\create_partner_budget.ps1:10 char:1
+ New-AzConsumptionBudget `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzConsumptionBudget], ErrorResponseException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Consumption.Cmdlets.Budget.NewAzureRmConsumptionBudget
 
DEBUG: AzureQoSEvent: CommandName - New-AzConsumptionBudget; IsSuccess - False; Duration - 00:00:02.3240402; Exception - Microsoft.Azure.Management.Consumption.Models.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
   at Microsoft.Azure.Management.Consumption.BudgetsOperations.<CreateOrUpdateWithHttpMessagesAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.<CreateOrUpdateAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.CreateOrUpdate(IBudgetsOperations operations, String budgetName, Budget parameters)
   at Microsoft.Azure.Commands.Consumption.Cmdlets.Budget.NewAzureRmConsumptionBudget.ExecuteCmdlet();
DEBUG: Finish sending metric.
DEBUG: 11:08:42 AM - NewAzureRmConsumptionBudget end processing.
DEBUG: 11:08:42 AM - NewAzureRmConsumptionBudget end processing.

Error output

DEBUG: 11:11:24 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 11:11:24 AM - using account id '[email protected]'...


   HistoryId: 27


Message        : Operation returned an invalid status code 'Unauthorized'
StackTrace     :    at Microsoft.Azure.Management.Consumption.BudgetsOperations.<CreateOrUpdateWithHttpMessagesAsync>d__8.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.<CreateOrUpdateAsync>d__7.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.Management.Consumption.BudgetsOperationsExtensions.CreateOrUpdate(IBudgetsOperations operations, String budgetName, Budget parameters)
                    at Microsoft.Azure.Commands.Consumption.Cmdlets.Budget.NewAzureRmConsumptionBudget.ExecuteCmdlet()
Exception      : Microsoft.Azure.Management.Consumption.Models.ErrorResponseException
InvocationInfo : {New-AzConsumptionBudget}
Line           : New-AzConsumptionBudget `

Position       : At D:\MyCloudProjects\CloudTeam\Scripts\Azure Code\Automation\Costing\create_partner_budget.ps1:10 char:1
                 + New-AzConsumptionBudget `
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 27



DEBUG: AzureQoSEvent: CommandName - Resolve-AzError; IsSuccess - True; Duration - 00:00:00.2848612; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 11:11:25 AM - ResolveError end processing.
DEBUG: 11:11:25 AM - ResolveError end processing.

DapiCloud avatar Aug 13 '19 15:08 DapiCloud

@bgsky @ms-premp Can you take alook?

markcowl avatar Aug 13 '19 22:08 markcowl

@DapiCloud is it a consistent repro for you ? Based on what I see, this seems to something transient. Please confirm, if this issue still persists or you were able to get past this.

ms-premp avatar Aug 14 '19 05:08 ms-premp

@DapiCloud I can confirm that you are able to create budgets.. hence closing this issue. Please let us know, if otherwise.

ms-premp avatar Aug 14 '19 06:08 ms-premp

Geez guys, can ya give me a little more that 30 min to respond here? lol

Issue is still happening, just confirmed again. Note, I have NEVER gotten this command to work using the repro code or any other.

I was able to successfully run New-AzResourceGroup under same PS session and that worked like a charm!

DapiCloud avatar Aug 14 '19 13:08 DapiCloud

@ms-premp can you take a look? I believe that the customer can make these changes through portal, but not PowerShell

markcowl avatar Aug 14 '19 21:08 markcowl

Anyone? @markcowl @ms-premp

DapiCloud avatar Aug 23 '19 13:08 DapiCloud

@ms-premp I am having this same issue in PowerShell and CloudShelll with both the New-AzConsumptionBudget and Set-AzConsumptionBudgt cmdlets. I have also confirmed the error is due to the parameter "-contactGroup"

zsiebers avatar Sep 04 '19 19:09 zsiebers

This is something reocurring very often, we do use New-AzDeployment to provision budget via ARM and 401 Unathorized is the almost all the time. Permissions we use are really fine... Can someone have a deeper look at it? Might be related to not fixed: https://github.com/Azure/azure-sdk-for-python/issues/4362

ghost avatar Sep 25 '19 09:09 ghost

@rkapso please take a look.

ms-premp avatar Sep 25 '19 17:09 ms-premp

@ms-premp @rkapso i have done plenty of test till now and found something. In our pipeline we create dates to put as Start & End for budget:

$date = Get-Date
$year = $date.Year
$month = $date.Month
$date = $date.AddYears(1)
$endYear = $date.Year
$startDate = Get-Date -Year $year -Month $month -Day 1
$endDate = Get-Date -Year $endYear -Month $month -Day 1
$startDateStr = '{0:yyyy-MM-dd}' -f $startDate
$endDateStr = '{0:yyyy-MM-dd}' -f $endDate

and then these are passed to the New-AzDeployment as parameters for Start & End... and we noticed that changing these dates to:

$startDateStr= ((Get-Date -Year $year -Month $month -Day 1).ToUniversalTime()).ToString("yyyy-MM-ddT00:00:00Z")
$endDateStr= ((Get-Date -Year $endYear -Month $month -Day 1).ToUniversalTime()).ToString("yyyy-MM-ddT00:00:00Z")

allows us to create the budget.

401 Unathorized is very not intuitive here. Can this be changed to proper error output?

ghost avatar Sep 26 '19 16:09 ghost

I had the same 401 error, and solved it by passing the id of my action group to -ContacGroup.

$actionGroupId = (Get-AzureRmActionGroup -ResourceGroupName 'myRgName' -Name 'myActionGroupName).id

New-AzConsumptionBudget -ResourceGroupName 'myRgName' -Name 'myBudgetName' -Amount 100 -Category Cost -TimeGrain Monthly -NotificationThreshold 100 -NotificationKey 'myNKey' -ContactEmail [email protected] -ContactGroup $actionGroupId -StartDate 2020-01-01 -EndDate 2020-01-31

Hope it helps.

handsomeppz avatar Jan 17 '20 02:01 handsomeppz

The thing here is that 401 is the error code in Azure Budgets for almost everything, no matter what is the real issue type. Bad json? Error 401. Incorrect paremeter? Error 401. Typo? Error 401. Terrible error handling.

ghost avatar Jan 19 '20 08:01 ghost

@tzheng27 That worked. I had the same problem where I tried to add the "-ContactGroup" parameter and it started failing. MS documentation says that it should be a system string which i think might need to be updated to clarify that it needs to be a string of the resource ID. https://docs.microsoft.com/en-us/powershell/module/az.billing/new-azconsumptionbudget?view=azps-3.4.0. Thanks for the information.

ghost avatar Feb 10 '20 18:02 ghost

@ms-premp any news on this issue?

toreskogoy avatar Feb 13 '20 13:02 toreskogoy

@rkapso Please verify.

ms-premp avatar Feb 13 '20 18:02 ms-premp

Team is investigating.

ramaganesan-rg avatar Jun 29 '20 17:06 ramaganesan-rg

I had the same 401 error, and solved it by passing the id of my action group to -ContacGroup.

$actionGroupId = (Get-AzureRmActionGroup -ResourceGroupName 'myRgName' -Name 'myActionGroupName).id

New-AzConsumptionBudget -ResourceGroupName 'myRgName' -Name 'myBudgetName' -Amount 100 -Category Cost -TimeGrain Monthly -NotificationThreshold 100 -NotificationKey 'myNKey' -ContactEmail [email protected] -ContactGroup $actionGroupId -StartDate 2020-01-01 -EndDate 2020-01-31

Hope it helps.

No, I have tried, Still, I am facing the issue "Bad Request"

mushamajay avatar Jul 01 '20 10:07 mushamajay

Latest doc (https://docs.microsoft.com/en-us/azure/cost-management-billing/costs/quick-create-budget-template?tabs=CLI) is explicit about using id instead of name of action group. Have you tried this?

ramaganesan-rg avatar Oct 19 '20 03:10 ramaganesan-rg

Closing this issue. Please feel free to reopen as needed.

ramaganesan-rg avatar Jan 26 '21 21:01 ramaganesan-rg

I still cant create budget due to "bad request" error, please help

trongmq avatar Jul 13 '23 15:07 trongmq