New-AzDiagnosticSetting

Create PSServiceDiagnosticSettings object.

Syntax

New-AzDiagnosticSetting
   -Name <String>
   [-StorageAccountId <String>]
   [-ServiceBusRuleId <String>]
   [-EventHubName <String>]
   [-EventHubAuthorizationRuleId <String>]
   [-WorkspaceId <String>]
   [-DedicatedLogAnalyticsDestinationType]
   [-Setting <PSDiagnosticDetailSettings[]>]
   [-ResourceId] <String>
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzDiagnosticSetting
   -Name <String>
   [-StorageAccountId <String>]
   [-ServiceBusRuleId <String>]
   [-EventHubName <String>]
   [-EventHubAuthorizationRuleId <String>]
   [-WorkspaceId <String>]
   [-Setting <PSDiagnosticDetailSettings[]>]
   [-SubscriptionId] <String>
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

Create PSServiceDiagnosticSettings object. This can be used as parameter -InputObject for Set-AzDiagnosticSetting

Examples

Example 1

$metric = New-AzDiagnosticDetailSetting -Metric -RetentionInDays 1 -RetentionEnabled -Category AllMetrics
$log = New-AzDiagnosticDetailSetting -Log -RetentionInDays 1 -RetentionEnabled -Category Audit -Enabled
$setting = New-AzDiagnosticSetting -TargetResourceId /subscriptions/XXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.Network/virtualNetworks/XXXXXXXX -Name diagnostic-test -WorkspaceId /subscriptions/XXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.OperationalInsights/workspaces/XXXXXXXXX -DedicatedLogAnalyticsDestinationType -Setting $log,$metric
Location                    :
Tags                        :
Id                          : /subscriptions/XXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.Network/virtualNetworks/XXXXXXXX/diagnosticSettings/diagnostic-test
Name                        : diagnostic-test
StorageAccountId            :
ServiceBusRuleId            :
EventHubAuthorizationRuleId :
EventHubName                :
Metrics
    TimeGrain       :
    Category        : AllMetrics
    Enabled         : False
    RetentionPolicy
    Enabled : True
    Days    : 1


Logs
    Category        : Audit
    Enabled         : True
    RetentionPolicy
    Enabled : True
    Days    : 1


WorkspaceId                 : /subscriptions/XXXXXXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.OperationalInsights/workspaces/XXXXXXXXX
LogAnalyticsDestinationType : Dedicated
Type                        :

Set-AzDiagnosticSetting -InputObject $setting

Create PSServiceDiagnosticSettings object. And create diagnostic setting for target resource.

Parameters

-DedicatedLogAnalyticsDestinationType

The value indicating whether to export (to ODS) to resource-specific (if present) or to AzureDiagnostics (default, not present)

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EventHubAuthorizationRuleId

The event hub rule id

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-EventHubName

The service bus rule id

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Name

The name of the diagnostic setting. Defaults to 'service'

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-ResourceId

The resource id

Type:String
Aliases:TargetResourceId
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-ServiceBusRuleId

The service bus rule id

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Setting

Metric settings or Log settings

Type:Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticDetailSettings[]
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-StorageAccountId

The storage account id

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-SubscriptionId

The subscription id

Type:String
Position:1
Default value:None
Accept pipeline input:True
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
Accept pipeline input:True
Accept wildcard characters:False

Inputs

String

SwitchParameter

Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticDetailSettings[]

Outputs

PSServiceDiagnosticSettings