Set-AzDiagnosticSetting
Sets the logs and metrics settings for the resource.
Syntax
Set-AzDiagnosticSetting
-ResourceId <String>
[-Name <String>]
[-StorageAccountId <String>]
[-ServiceBusRuleId <String>]
[-EventHubName <String>]
[-EventHubAuthorizationRuleId <String>]
[-Enabled <Boolean>]
[-Category <System.Collections.Generic.List`1[System.String]>]
[-MetricCategory <System.Collections.Generic.List`1[System.String]>]
[-Timegrain <System.Collections.Generic.List`1[System.String]>]
[-RetentionEnabled <Boolean>]
[-WorkspaceId <String>]
[-RetentionInDays <Int32>]
[-ExportToResourceSpecific]
[-EnableLog <Boolean>]
[-EnableMetrics <Boolean>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Set-AzDiagnosticSetting
-InputObject <PSServiceDiagnosticSettings>
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Set-AzDiagnosticSetting cmdlet enables or disables each time grain and log category for the particular resource. The logs and metrics are stored in the specified storage account. This cmdlet implements the ShouldProcess pattern, i.e. it might request confirmation from the user before actually creating, modifying, or removing the resource.
Examples
Example 1: Enable all metrics and logs for a resource
Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $True
This command enables all available metrics and logs for Resource01.
Example 2: Disable all metrics and logs
Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $False
This command disables all available metrics and logs for the resource Resource01.
Example 3: Enable/disable multiple metrics categories
Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $False -MetricCategory MetricCategory1,MetricCategory2
StorageAccountId : <storageAccountId>
StorageAccountName : <storageAccountName>
Metrics
Enabled : False
Category : MetricCategory1
Timegrain : PT1M
Enabled : False
Category : MetricCategory2
Timegrain : PT1H
Enabled : True
Category : MetricCategory3
Timegrain : PT1H
Logs
Enabled : True
Category : Category1
Enabled : True
Category : Category2
Enabled : True
Category : Category3
Enabled : False
Category : Category4
This command disables the metrics categories called Category1 and Category2. All the other categories remain the same.
Example 4: Enable/disable multiple log categories
Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $True -Category Category1,Category2
StorageAccountId : <storageAccountId>
StorageAccountName : <storageAccountName>
Metrics
Enabled : False
Category : MetricCategory1
Timegrain : PT1M
Enabled : False
Category : MetricCategory2
Timegrain : PT1H
Enabled : True
Category : MetricCategory3
Timegrain : PT1H
Logs
Enabled : True
Category : Category1
Enabled : True
Category : Category2
Enabled : True
Category : Category3
Enabled : False
Category : Category4
This command enables Category1 and Category2. All the other metrics and logs categories remain the same.
Example 5: Enable a time grain and multiple categories
Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $True -Category Category1,Category2 -Timegrain PT1M
This command enables only Category1, Category2, and time grain PT1M. All other time grains and categories are unchanged.
Example 6: Using pipeline
Get-AzDiagnosticSetting -ResourceId "Resource01" | Set-AzDiagnosticSetting -Enabled $True -Category Category1,Category2
This command uses the PowerShell pipeline to set (no change made) a diagnostic setting.
Example 7: Enable all categories for a subscription
$list = @()
Get-AzSubscriptionDiagnosticSettingCategory | ForEach-Object {
$list += (New-AzDiagnosticDetailSetting -Log -Category $_.Name -Enabled)
}
$DiagnosticSettingName = 'please use your setting name here'
$SubscriptionId = 'please use your subscription Id here'
$WorkspaceId = 'please use your workspace Id here'
$setting = New-AzDiagnosticSetting -Name $DiagnosticSettingName -SubscriptionId $SubscriptionId -WorkspaceId $WorkspaceId -Setting $list
Set-AzDiagnosticSetting -InputObject $setting
This command enabled all categories of logs for subscription.
Parameters
Specifies the list of log categories to enable or disable, according to the value of Enabled. If no category is specified, this command operates on all supported categories.
| Type: | List<T>[String] |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Prompts you for confirmation before running the cmdlet.
| Type: | SwitchParameter |
| Aliases: | cf |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
The credentials, account, tenant, and subscription used for communication with azure
| Type: | IAzureContextContainer |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
Indicates whether to enable diagnostics. Specify $True to enable diagnostics, or $False to disable diagnostics.
| Type: | Boolean |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The value indicating whether the diagnostic logs should be enabled or disabled
| Type: | Boolean |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The value indicating whether the diagnostic metrics should be enabled or disabled
| Type: | Boolean |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The event hub authorization rule id
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The event hub name
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Flag indicating that the export to LA must be done to a resource specific table, a.k.a. dedicated or fixed schema table, as opposed to the default dynamic schema table called AzureDiagnostics.
This argument is effective only when the argument -workspaceId is also given.
| Type: | SwitchParameter |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The input object (possible from the pipeline.) The name and resourceId will be extracted from this object.
| Type: | PSServiceDiagnosticSettings |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The list of metric categories. If no category is specified, this command operates on all supported categories.
| Type: | List<T>[String] |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The name of the diagnostic setting. The default value is service.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the ID of the resource.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Indicates whether retention of diagnostic information is enabled. Note that this only applies when saving data to a Storage account.
| Type: | Nullable<T>[Boolean] |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the retention policy, in days. Note that this only applies when saving data to a Storage account.
| Type: | Nullable<T>[Int32] |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
The Service Bus Rule id.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the ID of the Storage account in which to save the data.
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Specifies the time grains to enable or disable for metrics, according to the value of Enabled. If you do not specify a time grain, this command operates on all available time grains.
| Type: | List<T>[String] |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Shows what would happen if the cmdlet runs. The cmdlet is not run.
| Type: | SwitchParameter |
| Aliases: | wi |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
The resource Id of the Log Analytics workspace to send logs/metrics to
| Type: | String |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
Inputs
List<T>[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Nullable<T>[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Nullable<T>[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Outputs
Related Links
الملاحظات
إرسال الملاحظات وعرضها المتعلقة بـ