如何使用PowerShell在Azure SQL数据库中启用诊断?
我正在使用Powershell& amp;创建数据库。创建数据库后的同一时间,我想启用保留日为1的诊断日志
任何帮助,非常感谢。
答案 0 :(得分:1)
是的,我们可以使用PowerShell命令Set-AzureRmDiagnosticSetting
启用它,这是我的脚本:
$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 :