Set-AzureRmDiagnosticSetting

Sets the logs and metrics settings for the resource.

Syntax

Set-AzureRmDiagnosticSetting
   -ResourceId <String>
   [-StorageAccountId <String>]
   [-ServiceBusRuleId <String>]
   [-EventHubAuthorizationRuleId <String>]
   [-Enabled <Boolean>]
   [-Categories <System.Collections.Generic.List`1[System.String]>]
   [-Timegrains <System.Collections.Generic.List`1[System.String]>]
   [-RetentionEnabled <Boolean>]
   [-WorkspaceId <String>]
   [-RetentionInDays <Int32>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The Set-AzureRmDiagnosticSetting 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-AzureRmDiagnosticSetting -ResourceId "Resource01" -Enabled $True

This command enables all available metrics and logs for Resource01.

Example 2: Disable all metrics and logs

PS C:\>Set-AzureRmDiagnosticSetting -ResourceId "Resource01" -Enabled $False

This command disables all available metrics and logs for the resource Resource01.

Example 3: Enable multiple categories

PS C:\>Set-AzureRmDiagnosticSetting -ResourceId "Resource01" -Enabled $True -Categories Category1,Category2
StorageAccountId   : <storageAccountId>
StorageAccountName : <storageAccountName>
Metrics
Enabled   : True
Timegrain : PT1M
Enabled   : True
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 timegrains and other categories remain the same.

Example 4: Enable a time grain and multiple categories

PS C:\>Set-AzureRmDiagnosticSetting -ResourceId "Resource01" -Enabled $True -Categories Category1,Category2 -Timegrains PT1M

This command enables only Category1, Category2, and time grain PT1M. All other time grains and categories are unchanged.

Required Parameters

-ResourceId

Specifies the ID of the resource.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Optional Parameters

-Categories

Specifies the list of log categories to enable or disable, according to the value of Enabled. If you do not specify a category, this command operates on all categories.

Type:System.Collections.Generic.List`1[System.String]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Confirm

Prompts you for confirmation before running the cmdlet.

Type:System.Management.Automation.SwitchParameter
Aliases:cf
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
Default value:None
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
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-EventHubAuthorizationRuleId

The event hub rule i

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RetentionEnabled

Indicates whether retention of diagnostic information is enabled.

Type:System.Nullable`1[System.Boolean]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RetentionInDays

Specifies the retention policy, in days.

Type:System.Nullable`1[System.Int32]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ServiceBusRuleId
Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
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
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Timegrains

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:System.Collections.Generic.List`1[System.String]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:System.Management.Automation.SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WorkspaceId

The Id of the workspace

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Outputs

Microsoft.Azure.Commands.Insights.OutputClasses.PSServiceDiagnosticSettings