Skip to content

Commit 30a3240

Browse files
authored
Merge pull request #101779 from Ayanmullick/patch-3
Updating Diagnostic Setting creation per Az PowerShell 9.1.0 version of Az.Monitor
2 parents 35460a7 + 862ed35 commit 30a3240

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
@@ -205,15 +205,23 @@ After a few moments, the new setting appears in your list of settings for this r
205205

206206
# [PowerShell](#tab/powershell)
207207

208-
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.
208+
Use the [New-AzDiagnosticSetting](/powershell/module/az.monitor/new-azdiagnosticsetting?view=azps-9.1.0&preserve-view=true) cmdlet to create a diagnostic setting with [Azure PowerShell](../powershell-samples.md). See the documentation for this cmdlet for descriptions of its parameters.
209209

210210
> [!IMPORTANT]
211211
> 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.
212212
213-
The following example PowerShell cmdlet creates a diagnostic setting by using all three destinations.
213+
The following example PowerShell cmdlet creates a diagnostic setting for all logs and metrics for a key vault by using Log Analytics Workspace.
214214

215215
```powershell
216-
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
216+
$KV= Get-AzKeyVault -ResourceGroupName <resource group name> -VaultName <key vault name>
217+
$Law= Get-AzOperationalInsightsWorkspace -ResourceGroupName <resource group name> -Name <workspace name> #LAW name is case sensitive
218+
219+
$metric = @()
220+
$log = @()
221+
$metric += New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category AllMetrics -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
222+
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -CategoryGroup allLogs -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
223+
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -CategoryGroup audit -RetentionPolicyDay 30 -RetentionPolicyEnabled $true
224+
New-AzDiagnosticSetting -Name 'KeyVault-Diagnostics' -ResourceId $KV.ResourceId -WorkspaceId $Law.ResourceId -Log $log -Metric $metric -Verbose
217225
```
218226

219227
# [CLI](#tab/cli)
@@ -301,4 +309,4 @@ Every effort is made to ensure all log data is sent correctly to your destinatio
301309

302310
## Next step
303311

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

0 commit comments

Comments
 (0)