Set-AzureRmDiagnosticSetting
Sets the logs and metrics settings for the resource.
Warning
The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.
Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.
Syntax
Set-AzureRmDiagnosticSetting
-ResourceId <String>
[-Name <String>]
[-StorageAccountId <String>]
[-ServiceBusRuleId <String>]
[-EventHubName <String>]
[-EventHubAuthorizationRuleId <String>]
[-Enabled <Boolean>]
[-Categories <System.Collections.Generic.List`1[System.String]>]
[-MetricCategory <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>]
Set-AzureRmDiagnosticSetting
-InputObject <PSServiceDiagnosticSettings>
[-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/disable multiple metrics categories
PS C:\>Set-AzureRmDiagnosticSetting -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 enables the metrics cateories called Category1 and Category2. All the other categories remain the same.
Example 4: Enable/disable multiple log categories
PS C:\>Set-AzureRmDiagnosticSetting -ResourceId "Resource01" -Enabled $True -Categories 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-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.
Example 5: Using pipeline
PS C:\>Get-AzureRmDiagnosticSetting -ResourceId "Resource01" | Set-AzureRmDiagnosticSetting
This command uses the PowerShell pipeline to set (not change made) a diagnostic setting.
Parameters
-Categories
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] |
Aliases: | Category |
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: | 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 |
-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 |
-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: | List<T>[String] |
Aliases: | Timegrain |
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 Id of the workspace
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
Parameters: InputObject (ByValue)
List<T>[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Nullable<T>[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Nullable<T>[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]