Skip to content

Commit 5376100

Browse files
authored
Update diagnostic-settings.md
`Set-AzDiagnosticSetting` is not available in the current version of the PowerShell module. I updated the steps based on the current version of the module. Please review and approve.
1 parent 81ecbd0 commit 5376100

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

articles/azure-monitor/essentials/diagnostic-settings.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,23 @@ After a few moments, the new setting appears in your list of settings for this r
192192

193193
# [PowerShell](#tab/powershell)
194194

195-
Use the [Set-AzDiagnosticSetting](/powershell/module/az.monitor/set-azdiagnosticsetting) cmdlet to create a diagnostic setting with [Azure PowerShell](../powershell-samples.md). See the documentation for this cmdlet for descriptions of its parameters.
195+
Use the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting?view=azps-9.1.0) cmdlet to create a diagnostic setting with [Azure PowerShell](../powershell-samples.md). See the documentation for this cmdlet for descriptions of its parameters.
196196

197197
> [!IMPORTANT]
198198
> You can't use this method for an activity log. Instead, use [Create diagnostic setting in Azure Monitor by using an Azure Resource Manager template](./resource-manager-diagnostic-settings.md) to create a Resource Manager template and deploy it with PowerShell.
199199
200-
The following example PowerShell cmdlet creates a diagnostic setting by using all three destinations.
200+
The following example PowerShell cmdlet creates a diagnostic setting for all logs and metrics for a key vault by using Log Analytics Workspace.
201201

202202
```powershell
203-
Set-AzDiagnosticSetting -Name KeyVault-Diagnostics -ResourceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.KeyVault/vaults/mykeyvault -Category AuditEvent -MetricCategory AllMetrics -Enabled $true -StorageAccountId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount -WorkspaceId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/oi-default-east-us/providers/microsoft.operationalinsights/workspaces/myworkspace -EventHubAuthorizationRuleId /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.EventHub/namespaces/myeventhub/authorizationrules/RootManageSharedAccessKey
203+
$KV= Get-AzKeyVault -ResourceGroupName <resource group name> -VaultName <key vault name>
204+
$Law= Get-AzOperationalInsightsWorkspace -ResourceGroupName <resource group name> -Name <workspace name> #LAW name is case sensitive
205+
206+
$metric = @()
207+
$log = @()
208+
$metric += New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category AllMetrics -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
209+
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -CategoryGroup allLogs -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
210+
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -CategoryGroup audit -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
211+
New-AzDiagnosticSetting -Name 'KeyVault-Diagnostics' -ResourceId $KV.ResourceId -WorkspaceId $Law.ResourceId -Log $log -Metric $metric -Verbose
204212
```
205213

206214
# [CLI](#tab/cli)
@@ -288,4 +296,4 @@ Every effort is made to ensure all log data is sent correctly to your destinatio
288296

289297
## Next step
290298

291-
[Read more about Azure platform logs](./platform-logs-overview.md)
299+
[Read more about Azure platform logs](./platform-logs-overview.md)

0 commit comments

Comments
 (0)