{"id":7428,"date":"2023-12-06T10:58:43","date_gmt":"2023-12-06T10:58:43","guid":{"rendered":"https:\/\/rakhesh.com\/?p=7428"},"modified":"2023-12-06T10:58:43","modified_gmt":"2023-12-06T10:58:43","slug":"new-azdatacollectionruleassociation-operation-returned-an-invalid-status-code-badrequest","status":"publish","type":"post","link":"https:\/\/rakhesh.com\/azure\/new-azdatacollectionruleassociation-operation-returned-an-invalid-status-code-badrequest\/","title":{"rendered":"New-AzDataCollectionRuleAssociation – Operation returned an invalid status code ‘BadRequest’"},"content":{"rendered":"

Was trying to associate some data collection rules in Azure and the cmdlet kept throwing up this unhelpful error:<\/p>\n

Exception type: ErrorResponseCommonV2Exception, Message: Microsoft.Azure.Management.Monitor.Models.ErrorResponseCommonV2Exception: Operation returned an invalid status code 'BadRequest' at Microsoft.Azure.Management.Monitor.DataCollectionRuleAssociationsOperations.<CreateWithHttpMessagesAsync>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.Monitor.DataCollectionRuleAssociationsOperationsExtensions.<CreateAsync>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.Monitor.DataCollectionRuleAssociationsOperationsExtensions.Create(IDataCollectionRuleAssociationsOperations operations, String resourceUri, String associationName, DataCollectionRuleAssociationProxyOnlyResource body) at Microsoft.Azure.Commands.Insights.DataCollectionRules.NewAzureRmDataCollectionRuleAssociationCommand.ProcessRecordInternalByDataCollectionRuleId() at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet(), Code: Null, Status code:Null, Reason phrase: Null<\/pre>\n

After a bit of trial and error I figured out the issue. The association name shouldn’t contain spaces etc. I was doing -AssociationName \"blah blah\"<\/code> while it should have been -AssociationName \"blah-blah\"<\/code>.<\/p>\n

Could have just told me that! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"

Was trying to associate some data collection rules in Azure and the cmdlet kept throwing up this unhelpful error: Exception type: ErrorResponseCommonV2Exception, Message: Microsoft.Azure.Management.Monitor.Models.ErrorResponseCommonV2Exception: Operation returned an invalid status code ‘BadRequest’ at Microsoft.Azure.Management.Monitor.DataCollectionRuleAssociationsOperations.<CreateWithHttpMessagesAsync>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.Monitor.DataCollectionRuleAssociationsOperationsExtensions.<CreateAsync>d__7.MoveNext() — End … Continue reading New-AzDataCollectionRuleAssociation – Operation returned an invalid status code ‘BadRequest’<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[887],"tags":[],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7428"}],"collection":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/comments?post=7428"}],"version-history":[{"count":1,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7428\/revisions"}],"predecessor-version":[{"id":7429,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7428\/revisions\/7429"}],"wp:attachment":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/media?parent=7428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/categories?post=7428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/tags?post=7428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}