1

enter image description here

How can I enable diagnostics in Azure SQL Database using PowerShell?

I am creating the database using Powershell & same time after creating DB, I want to enable Diagnostic logs with Retention days as 1

Any help, highly appreciated.

1 Answer 1

1

Yes, we can use PowerShell command Set-AzureRmDiagnosticSetting to enable it, here is my script:

$storage = Get-AzureRmStorageAccount -ResourceGroupName sql -Name jasondisk321
$storageid = $storage.id
$resoure = Find-AzureRmResource -ResourceNameContains "sql"
$id = $resoure.ResourceId
PS C:\windows\system32> Set-AzureRmDiagnosticSetting -ResourceId $id -StorageAccountId $storageid -RetentionEnabled $true -RetentionInDays "1" -Enabled $true


StorageAccountId : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/sql/providers/Microsoft.Storage/storageAccounts/jasondisk321
ServiceBusRuleId :
Metrics          : {Microsoft.Azure.Management.Insights.Models.MetricSettings}
Logs             : {}
WorkspaceId      :
Id               : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourcegroups/sql/providers/microsoft.sql/servers/jason321/databases/jasonsql/providers/microsoft.insights/diagnosticSettings/service
Name             : service
Type             :
Location         :
Tags             :
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.