Reputation: 731
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.
Upvotes: 1
Views: 1038
Reputation: 13954
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 :
Upvotes: 1