Edit

Share via


Set-AzDiagnosticSetting

Sets the logs and metrics settings for the resource.

Syntax

OldSetDiagnosticSetting (Default)

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>]

NewSetDiagnosticSetting

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.

Parameter properties

Type:

List<T>[String]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DefaultProfile

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

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Enabled

Indicates whether to enable diagnostics. Specify $True to enable diagnostics, or $False to disable diagnostics.

Parameter properties

Type:Boolean
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-EventHubAuthorizationRuleId

The event hub authorization rule id

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-EventHubName

The event hub name

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments: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.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-InputObject

The input object (possible from the pipeline.) The name and resourceId will be extracted from this object.

Parameter properties

Type:PSServiceDiagnosticSettings
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

NewSetDiagnosticSetting
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-MetricCategory

The list of metric categories. If no category is specified, this command operates on all supported categories.

Parameter properties

Type:

List<T>[String]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

The name of the diagnostic setting. The default value is service.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ResourceId

Specifies the ID of the resource.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-RetentionEnabled

Indicates whether retention of diagnostic information is enabled.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-RetentionInDays

Specifies the retention policy, in days.

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ServiceBusRuleId

The Service Bus Rule id.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-StorageAccountId

Specifies the ID of the Storage account in which to save the data.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments: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.

Parameter properties

Type:

List<T>[String]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-WhatIf

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WorkspaceId

The resource Id of the Log Analytics workspace to send logs/metrics to

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

OldSetDiagnosticSetting
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

PSServiceDiagnosticSettings

String

Boolean

List<T>

Nullable<T>

Nullable<T>

Outputs

PSServiceDiagnosticSettings