Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Set-AzDiagnosticSetting : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request #9689

Closed SwathiDhanwada-MSFT closed 5 years ago

SwathiDhanwada-MSFT commented 5 years ago

Description

Set-AzDiagnosticSetting cmdlet execution fails with error" Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request"

Steps to reproduce

PS Azure:\> Set-AzDiagnosticSetting -ResourceId /subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName -Enabled $true -WorkspaceId 1c11b111-111e-1f11-b111-beef1111c1e1
WARNING: 6:08:08 AM - *** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.
WARNING: 6:08:08 AM - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.
Set-AzDiagnosticSetting : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request
At line:1 char:1
+ Set-AzDiagnosticSetting -ResourceId /subscriptions/b83c1ed3-c5b6-44fb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Set-AzDiagnosticSetting], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.1
PSEdition                      Core
GitCommitId                    6.2.1
OS                             Linux 4.15.0-1050-azure #55-Ubuntu SMP Sat Jun 29 00:27:54 UTC 2019
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

 Directory: /usr/local/share/powershell/Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     2.4.0      Az                                  Core,Desk
Script     1.6.0      Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-…
Script     1.0.0      Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Disable-AzAdvisorRecomme…
Script     1.0.1      Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCredential…}
Script     1.1.0      Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServ…
Script     1.2.0      Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManageme…
Script     1.0.0      Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzApplicationInsights, Remove-AzApplicationInsights, S…
Script     1.3.0      Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomationHybridWorkerGroup, Get-AzAutoma…
Script     1.1.0      Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKey, New-AzBatchAccount…}
Script     1.0.0      Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumption…
Script     1.3.0      Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnProfile, Remove-AzCdnProfile…}
Script     1.1.1      Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveSer…
Script     2.4.0      Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAvailabilitySet, Update-AzAvai…
Script     1.0.1      Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzContainerGroup, Get-AzContainerI…
Script     1.0.1      Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContainerRegistry, Update-AzContainerRegistry, Remove-…
Script     1.1.2      Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDataFactoryV2, Remove-AzDataFactor…
Script     1.0.0      Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-A…
Script     1.2.1      Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove…
Script     1.0.0      Az.DeploymentManager                Core,Desk {Get-AzDeploymentManagerArtifactSource, New-AzDeploymentManagerArtifactSource, Set-AzD…
Script     1.0.0      Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy,…
Script     1.1.1      Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet…}
Script     1.2.1      Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopi…
Script     1.2.0      Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-AzEventHubNamespace, Remove-AzE…
Script     1.1.0      Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor…}
Script     0.10.6     Az.GuestConfiguration               Core,Desk {Get-AzVMGuestPolicyStatus, Get-AzVMGuestPolicyStatusHistory}
Script     2.0.0      Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition, Wait-AzHDInsightJob, New-AzHDI…
Script     1.2.0      Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get…
Script     1.2.0      Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificate, Stop-AzKeyVaultCertificateOp…
Script     1.2.1      Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegratio…
Script     1.1.0      Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlan…
Script     1.0.0      Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.1.0      Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get-AzMediaServiceKey, Get-AzMe…
Script     1.2.1      Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProfile, Get-AzLogProfile…}
Script     1.11.0     Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate, Get-AzApplicationGatewayAuthentica…
Script     1.1.0      Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRule, Get-AzNotificationHubL…
Script     1.3.1      Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomL…
Script     1.1.2      Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediati…
Script     1.1.0      Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWorkspaceCollection, Get-AzPowerBIW…
Script     1.4.2      Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRecoveryServicesVault, Get-AzRecoveryServ…
Script     1.1.0      Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheScheduleEntry, Get-AzRedisCachePatc…
Script     1.0.1      Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRelayNamespace, Remove-AzRelayNames…
Script     1.6.0      Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRoleAssignment, New-AzRoleAss…
Script     1.2.1      Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, Set-AzServiceBusNamespace, Remo…
Script     1.1.1      Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricApplicationCertificate, Add-AzServiceFabricClientCertificate, Add-…
Script     1.0.2      Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey…}
Script     1.13.0     Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptio…
Script     1.5.0      Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStorageAccount, New-AzStorageAcc…
Script     1.1.1      Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck, New-AzStorageSyncService, Get-AzStorageSyncSe…
Script     1.0.0      Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDefaultFunctionDefinition, New-Az…
Script     1.0.1      Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEn…
Script     1.3.0      Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppServicePlan, Remove-AzAppService…
Script     0.0.0.9    AzureAD.Standard.Preview            Desk      {Get-AzureADTenantDetail, Select-AzureADGroupIdsUserIsMemberOf, Select-AzureADGroupIds…
Script     0.9.3      AzurePSDrive                        Desk
Script     17.0.2985… EXOPSSessionConnector               Desk      Connect-EXOPSSession
Manifest   1.0.613    MicrosoftPowerBIMgmt                Desk
Binary     1.0.613    MicrosoftPowerBIMgmt.Admin          Desk      {Add-PowerBIEncryptionKey, Get-PowerBIEncryptionKey, Get-PowerBIWorkspaceEncryptionSta…
Binary     1.0.613    MicrosoftPowerBIMgmt.Capacities     Desk      Get-PowerBICapacity
Binary     1.0.613    MicrosoftPowerBIMgmt.Data           Desk      {Add-PowerBIDataset, Set-PowerBITable, New-PowerBIDataset, New-PowerBITable…}
Binary     1.0.613    MicrosoftPowerBIMgmt.Profile        Desk      {Connect-PowerBIServiceAccount, Disconnect-PowerBIServiceAccount, Invoke-PowerBIRestMe…
Binary     1.0.613    MicrosoftPowerBIMgmt.Reports        Desk      {Get-PowerBIReport, New-PowerBIReport, Export-PowerBIReport, Get-PowerBIDashboard…}
Binary     1.0.613    MicrosoftPowerBIMgmt.Workspaces     Desk      {Get-PowerBIWorkspace, Add-PowerBIWorkspaceUser, Remove-PowerBIWorkspaceUser, Set-Powe…
Script     0.9.3      PSCloudShellUtility                 Desk      {Enter-AzVM, Get-AzCommand, Invoke-AzVMCommand, Enable-AzVMPSRemoting…}
Binary     0.8.1      SHiPS                               Desk
Script     21.1.18135 SqlServer                           Desk      {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp…

    Directory: /opt/microsoft/powershell/6/Modules

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Manifest   1.2.3.0    Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   6.1.0.0    Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   6.1.0.0    Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path…}
Manifest   6.1.0.0    Microsoft.PowerShell.Security       Core      {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-SecureString…}
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias, New-Alias…}
Script     1.3.2      PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource…}
Script     2.1.3      PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability…}
Script     0.0        PSDesiredStateConfiguration         Desk      {Write-MetaConfigFile, Set-NodeResources, Get-DSCResourceModules, Set-PSTopConfigurati…
Script     2.0.0      PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remove-PSReadLineKeyHandler, Get-…
Binary     1.1.2      ThreadJob                           Desk      Start-ThreadJob

Debug output

DEBUG: 6:25:10 AM - Processing using command line arguments
DEBUG: 6:25:10 AM - Listing existing diagnostics settings for resourceId '/subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName'
DEBUG: [Common.Authentication]: Authenticating using Account: 'MSI@50342', environment: 'AzureCloud', tenant: '1c11b111-111e-1f11-b111-beef1111c1e1'
DEBUG: [HttpClientOperations]: Adding Header 'Metadata'
DEBUG: Checking Cache request http://localhost:50342/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01
DEBUG: Cache Hit
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName/providers/microsoft.insights/diagnosticSettings?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : e332ceaa-1034-423b-8324-ef30175d704d
Accept-Language               : en-US

Body:

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

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : 5fc90146-fc56-42f9-96d8-3fb9ac9b4ba2
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id   : a70094a0-006b-4451-85a1-41d166b8b888
x-ms-routing-request-id       : WESTINDIA:20190719T062511Z:a70094a0-006b-4451-85a1-41d166b8b888
X-Content-Type-Options        : nosniff
Date                          : Fri, 19 Jul 2019 06:25:11 GMT

Body:
{
  "value": []
}

DEBUG: 6:25:11 AM - Diagnostic setting named: 'service' not found in list of 0 settings. Creating a new one.
DEBUG: 6:25:12 AM - Retrieving supported categories for resource: '/subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com//subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName/providers/microsoft.insights/diagnosticSettingsCategories?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : c158c726-4d5d-4a22-9ddb-e101e57d1b43
Accept-Language               : en-US

Body:

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

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-request-id               : f95f87e7-9cf1-4fc7-92f4-ef3c134f9e9b
Server                        : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11998
x-ms-correlation-request-id   : 653bbf1e-1e59-42ef-9f12-3f6927742fb7
x-ms-routing-request-id       : WESTINDIA:20190719T062512Z:653bbf1e-1e59-42ef-9f12-3f6927742fb7
X-Content-Type-Options        : nosniff
Date                          : Fri, 19 Jul 2019 06:25:11 GMT

Body:
{
  "value": [
    {
      "id": "/subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName/providers/microsoft.insights/diagnosticSettingsCategories/AllMetrics",
      "type": "microsoft.insights/diagnosticSettingsCategories",
      "name": "AllMetrics",
      "location": null,
      "kind": null,
      "tags": null,
      "properties": {
        "categoryType": "Metrics"
      },
      "identity": null
    }
  ]
}

DEBUG: 6:25:12 AM - Setting supported categories for resource: '/subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName'
DEBUG: 6:25:12 AM - Merging data. Existing setting is: not null
DEBUG: 6:25:12 AM - Setting workspace Id
DEBUG: 6:25:12 AM - Changing the enable properties
DEBUG: 6:25:12 AM - Setting Enabled property for logs
DEBUG: 6:25:12 AM - Setting Enabled property for metrics
DEBUG: 6:25:12 AM - Copying diagnostic settings
DEBUG: 6:25:12 AM - Sending create/update request setting: service
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com//subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName/providers/microsoft.insights/diagnosticSettings/service?api-version=2017-05-01-preview

Headers:
x-ms-client-request-id        : 5ed37082-b5b7-47f7-9246-6bfc9d4b2b0f
Accept-Language               : en-US

Body:
{
  "properties": {
    "metrics": [
      {
        "category": "AllMetrics",
        "enabled": true
      }
    ],
    "logs": [],
    "workspaceId": "1c11b111-111e-1f11-b111-beef1111c1e1"
  }
}

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

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-request-id               : c19e73a1-c987-4eef-a653-658357e4846a
x-ms-correlation-request-id   : c19e73a1-c987-4eef-a653-658357e4846a
x-ms-routing-request-id       : WESTINDIA:20190719T062512Z:c19e73a1-c987-4eef-a653-658357e4846a
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Fri, 19 Jul 2019 06:25:11 GMT

Body:
{
  "error": {
    "code": "LinkedInvalidPropertyId",
    "message": "Property id '1c11b111-111e-1f11-b111-beef1111c1e1' at path 'properties.workspaceId' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."
  }
}

Set-AzDiagnosticSetting : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request
At line:1 char:1
+ Set-AzDiagnosticSetting -ResourceId /subscriptions/111c1ef1-c1b1-11fb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Set-AzDiagnosticSetting], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand

DEBUG: AzureQoSEvent: CommandName - Set-AzDiagnosticSetting; IsSuccess - False; Duration - 00:00:05.6235470; Exception - System.Management.Automation.PSInvalidOperationException: Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request ---> Microsoft.Azure.Management.Monitor.Models.ErrorResponseException: Operation returned an invalid status code 'BadRequest'
   at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.CreateOrUpdateWithHttpMessagesAsync(String resourceUri, DiagnosticSettingsResource parameters, String name, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.CreateOrUpdateAsync(IDiagnosticSettingsOperations operations, String resourceUri, DiagnosticSettingsResource parameters, String name, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 6:25:12 AM - SetAzureRmDiagnosticSettingCommand end processing.
DEBUG: 6:25:12 AM - SetAzureRmDiagnosticSettingCommand end processing.

Error output

   HistoryId: 9
Message        : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:BadRequest, Reason phrase: Bad Request
StackTrace     :    at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {Set-AzDiagnosticSetting}
Line           : Set-AzDiagnosticSetting -ResourceId /subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName -Enabled $true -WorkspaceId 1c11b111-111e-1f11-b111-beef1111c1e1 -Debug
Position       : At line:1 char:1
                 + Set-AzDiagnosticSetting -ResourceId /subscriptions/111c1ef1-c1b1-11fb ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 9

Message        : Operation returned an invalid status code 'BadRequest'
StackTrace     :    at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.CreateOrUpdateWithHttpMessagesAsync(String resourceUri,
                 DiagnosticSettingsResource parameters, String name, Dictionary`2 customHeaders, CancellationToken cancellationToken)
                    at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.CreateOrUpdateAsync(IDiagnosticSettingsOperations
                 operations, String resourceUri, DiagnosticSettingsResource parameters, String name, CancellationToken cancellationToken)
Exception      : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException
InvocationInfo : {Set-AzDiagnosticSetting}
Line           : Set-AzDiagnosticSetting -ResourceId /subscriptions/subscriptionID/resourceGroups/RG/providers/Microsoft.Compute/virtualMachines/VMName -Enabled $true -WorkspaceId 1c11b111-111e-1f11-b111-beef1111c1e1 -Debug
Position       : At line:1 char:1
                 + Set-AzDiagnosticSetting -ResourceId /subscriptions/111c1ef1-c1b1-11fb ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 9
SwathiDhanwada-MSFT commented 5 years ago

Set-AzDiagnosticSetting -ResourceId "/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts/Test-StanAA" -WorkspaceId "/subscriptions//resourceGroups//providers/Microsoft.OperationalInsights/workspaces/test-stan1" -Enabled $true

As you can see we are not using the workspace ID but rather the resource id of the workspace. Besides the documentation not being explicit on the parameter, the parameter itself is not well named as well.