In Azure Data Factory, I want to change the Diagnostic Settings to "Resource Specific" destination table using PowerShell. I have the existing settings which is sending logs to "Azure Diagnostics" tables. I want to change this default setting using PowerShell and to avoid the full diagnostic setting deployment again.
1 Answers
You could use the command below, in my sample, joyfactory
is my datafactory name, joyfactorydia
is the diagnosticSetting name, replace them and the <subscription-id>
and <group-name>
in the command.
Also make sure your Az.Accounts
powershell module is not too old, at least has the new command Invoke-AzRestMethod
, if it is old, you could use Update-Module -Name Az.Accounts
to update it.
Invoke-AzRestMethod -Method PUT -Path "/subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.DataFactory/factories/joyfactory/providers/microsoft.insights/diagnosticSettings/joyfactorydia?api-version=2017-05-01-preview" `
-Payload '{
"id": "/subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.DataFactory/factories/joyfactory/providers/microsoft.insights/diagnosticSettings/joyfactorydia",
"name": "joyfactorydia",
"properties": {
"logs": [{
"category": "ActivityRuns",
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "PipelineRuns",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "TriggerRuns",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISPackageEventMessages",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISPackageExecutableStatistics",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISPackageEventMessageContext",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISPackageExecutionComponentPhases",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISPackageExecutionDataStatistics",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}, {
"category": "SSISIntegrationRuntimeLogs",
"enabled": false,
"retentionPolicy": {
"days": 0,
"enabled": false
}
}],
"metrics": [{
"enabled": true,
"retentionPolicy": {
"days": 0,
"enabled": false
},
"category": "AllMetrics"
}],
"workspaceId": "/subscriptions/<subscription-id>/resourcegroups/<group-name>/providers/microsoft.operationalinsights/workspaces/joylogana",
"logAnalyticsDestinationType": "Dedicated"
}
}'
In the Payload
, "logAnalyticsDestinationType": "Dedicated"
is what you want, it changes the Destination table
to Resource specific
. For other values, you could refer to the result of the commands below, then fix them using the format in the Payload
above.
$id = (Get-AzDataFactoryV2 -ResourceGroupName <group-name> -Name joyfactory).DataFactoryId
Get-AzDiagnosticSetting -Name joyfactorydia -ResourceId $id
Besides, I have also tried Set-AzDiagnosticSetting
and Set-AzResource
, both not work, there are maybe some bugs, not write them in detail here.
If you can accept to use the Azure CLI, there is the easiest way:
$id = (Get-AzDataFactoryV2 -ResourceGroupName <group-name> -Name joyfactory).DataFactoryId
$dia = Get-AzDiagnosticSetting -Name joyfactorydia -ResourceId $id
az resource update --ids $dia.Id --api-version '2017-05-01-preview' --set properties.logAnalyticsDestinationType=Dedicated