Home > Blockchain >  Can't remove diagnostic settings from storage account
Can't remove diagnostic settings from storage account

Time:02-18

I am creating a script for deleting all diagnostic settings. But I have a problem with Storage Accounts. Because the script only removes diagnostic settings on the top level. But for Blobs, Queues, Files and Tables, the diagnostic settings are still there...

$storage = Get-AzResource -Name "storageaccountpointa110"'
$id = $storage.ResourceId
Remove-AzDiagnosticSetting -ResourceId $id

This is the output: Diagnostic Settings from tenant

CodePudding user response:

I have tested in my environment

Remove-AzDiagnosticSetting takes only the Resource ID

As the Resource IDs of blob, queue, file and table are different from storage account Resource ID, your script only deletes the diagnostic settings of the storage account.

To remove the diagnostic settings of the storage account along with blob, queue, file and table, you can use below script:

$account = Get-AzResource -Name "StorageAccountName"
$accountResID = $account.ID
$blobResID = $account.ID   "/blobServices/default"
$fileResID = $account.ID   "/fileServices/default"
$queueResID = $account.ID   "/queueServices/default"
$tableResID = $account.ID   "/tableServices/default"
Remove-AzDiagnosticSetting -ResourceId $accountResID
Remove-AzDiagnosticSetting -ResourceId $blobResID
Remove-AzDiagnosticSetting -ResourceId $fileResID
Remove-AzDiagnosticSetting -ResourceId $queueResID
Remove-AzDiagnosticSetting -ResourceId $tableResID
  • Related