Search code examples
azurepowershelldiagnosticsazure-log-analyticsazure-diagnostics

ResourceType mismatch in Set-AzDiagnosticSetting


I want to update (not create) existing Diagnostic Settings entries for network related resources, they miss retention days variables and workspace assignment, but when I use this command:

$WorkspaceId = "..."
$ResourceId = "..."   
Set-AzDiagnosticSetting -resourceid $ResourceId -RetentionEnabled $True -RetentionInDays 31 -WorkspaceId $WorkspaceId

I get this error:

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

When I use alternative way of

$get = Get-AzDiagnosticSetting -resourceid $ResourceId
Set-AzDiagnosticSetting -InputObject $get -MetricCategory AllMetrics -RetentionEnabled $True -RetentionInDays 31 -WorkspaceId $WorkspaceId

I get this error: Set-AzDiagnosticSetting : Parameter set cannot be resolved using the specified named parameters.

Can I actually update the entry with Set-AzDiagnosticSetting or only create one? Or I'm stuck with removing all diagnostic settings entires for network objects and assigning them properly again?


Solution

  • If you do not pass the fully qualified ID of the Workspace, you get the below error:

    enter image description here But if you provide the correct Workspace ID i.e. fully qualified ID of the workspace you can get rid of this error.

    enter image description here

    And to use the alternative way, use it in this way, as mentioned in the documentation (Example 5: Using pipeline).

    Get-AzDiagnosticSetting -ResourceId "Resource01" | Set-AzDiagnosticSetting -Enabled $True -Category Category1,Category2