Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

New-AzDiagnosticSetting

Create diagnostic settings for the specified resource.

Syntax

CreateExpanded (Default)

New-AzDiagnosticSetting
 -Name <String>
 -ResourceId <String>
 [-EventHubAuthorizationRuleId <String>]
 [-EventHubName <String>]
 [-Log <ILogSettings[]>]
 [-LogAnalyticsDestinationType <String>]
 [-MarketplacePartnerId <String>]
 [-Metric <IMetricSettings[]>]
 [-ServiceBusRuleId <String>]
 [-StorageAccountId <String>]
 [-WorkspaceId <String>]
 [-DefaultProfile <PSObject>]
 [-WhatIf]
 [-Confirm]
 [<CommonParameters>]

CreateViaJsonFilePath

New-AzDiagnosticSetting
 -Name <String>
 -ResourceId <String>
 -JsonFilePath <String>
 [-DefaultProfile <PSObject>]
 [-WhatIf]
 [-Confirm]
 [<CommonParameters>]

CreateViaJsonString

New-AzDiagnosticSetting
 -Name <String>
 -ResourceId <String>
 -JsonString <String>
 [-DefaultProfile <PSObject>]
 [-WhatIf]
 [-Confirm]
 [<CommonParameters>]

Description

Create diagnostic settings for the specified resource.

Examples

Example 1: Create diagnostic setting

$subscriptionId = (Get-AzContext).Subscription.Id
$metric = @()
$log = @()
$metric += New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category AllMetrics
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category ContainerEventLogs
New-AzDiagnosticSetting -Name test-setting -ResourceId /subscriptions/$subscriptionId/resourceGroups/test-rg-name/providers/Microsoft.AppPlatform/Spring/springcloud-001 -WorkspaceId /subscriptions/$subscriptionId/resourcegroups/test-rg-name/providers/microsoft.operationalinsights/workspaces/test-workspace -Log $log -Metric $metric

Create diagnostic setting for resource with log analytics workspace as destination

Example 2: Create diagnostic setting for all supported categories

$subscriptionId = (Get-AzContext).Subscription.Id
$metric = @()
$log = @()
$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/$subscriptionId/resourceGroups/test-rg-name/providers/Microsoft.AppPlatform/Spring/springcloud-001
$categories | ForEach-Object {if($_.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $_.Name} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name}}
New-AzDiagnosticSetting -Name test-setting -ResourceId /subscriptions/$subscriptionId/resourceGroups/test-rg-name/providers/Microsoft.AppPlatform/Spring/springcloud-001 -WorkspaceId /subscriptions/$subscriptionId/resourcegroups/test-rg-name/providers/microsoft.operationalinsights/workspaces/test-workspace -Log $log -Metric $metric

Create diagnostic setting for all supported categories

Parameters

-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

-DefaultProfile

The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.

Parameter properties

Type:PSObject
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzureRMContext, AzureCredential

Parameter sets

-EventHubAuthorizationRuleId

The resource Id for the event hub authorization rule.

Parameter properties

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

Parameter sets

-EventHubName

The name of the event hub. If none is specified, the default event hub will be selected.

Parameter properties

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

Parameter sets

-JsonFilePath

Path of Json file supplied to the Create operation

Parameter properties

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

Parameter sets

-JsonString

Json string supplied to the Create operation

Parameter properties

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

Parameter sets

-Log

The list of logs settings.

Parameter properties

Type:

ILogSettings[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-LogAnalyticsDestinationType

A string indicating whether the export to Log Analytics should use the default destination type, i.e. AzureDiagnostics, or use a destination type constructed as follows: <normalized service identity>_<normalized category name>. Possible values are: Dedicated and null (null is default.)

Parameter properties

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

Parameter sets

-MarketplacePartnerId

The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic Logs.

Parameter properties

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

Parameter sets

-Metric

The list of metric settings.

Parameter properties

Type:

IMetricSettings[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Name

The name of the diagnostic setting.

Parameter properties

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

Parameter sets

-ResourceId

The identifier of the resource.

Parameter properties

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

Parameter sets

-ServiceBusRuleId

The service bus rule Id of the diagnostic setting. This is here to maintain backwards compatibility.

Parameter properties

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

Parameter sets

-StorageAccountId

The resource ID of the storage account to which you would like to send Diagnostic Logs.

Parameter properties

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

Parameter sets

-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

-WorkspaceId

The full ARM resource ID of the Log Analytics workspace to which you would like to send Diagnostic Logs. Example: /subscriptions/4b9e8510-67ab-4e9a-95a9-e2f1e570ea9c/resourceGroups/insights-integration/providers/Microsoft.OperationalInsights/workspaces/viruela2

Parameter properties

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

Parameter sets

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.

Outputs

IDiagnosticSettingsResource


Feedback

Was this page helpful?