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>]
[-ExportToResourceSpecific]
[-RetentionInDays <Int32>]
[-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
PS C:\>Set-AzDiagnosticSetting -ResourceId "Resource01" -Enabled $True
This command enables all available metrics and logs for Resource01.
Example 2: Disable all metrics and logs
PS C:\>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
PS C:\>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
PS C:\>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 4: Enable a time grain and multiple categories
PS C:\>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 5: Using pipeline
PS C:\>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.
Parameters
-Category
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 |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure
Type: | IAzureContextContainer |
Aliases: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Enabled
Indicates whether to enable diagnostics. Specify $True to enable diagnostics, or $False to disable diagnostics.
Type: | Boolean |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-EventHubAuthorizationRuleId
The event hub authorization rule id
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-EventHubName
The event hub name
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ExportToResourceSpecific
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 |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-InputObject
The input object (possible from the pipeline.) The name and resourceId will be extracted from this object.
Type: | PSServiceDiagnosticSettings |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-MetricCategory
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 |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
The name of the diagnostic setting. The default value is service.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ResourceId
Specifies the ID of the resource.
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-RetentionEnabled
Indicates whether retention of diagnostic information is enabled.
Type: | Nullable<T>[Boolean] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-RetentionInDays
Specifies the retention policy, in days.
Type: | Nullable<T>[Int32] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ServiceBusRuleId
The Service Bus Rule id.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-StorageAccountId
Specifies the ID of the Storage account in which to save the data.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Timegrain
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 |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WorkspaceId
The resource Id of the Log Analytics workspace to send logs/metrics to
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
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]]