I need to create and enable a diagnostic setting at subscription level rather than resource level.
Azure CLI has the command
az monitor diagnostic-settings subscription create that allows me to achieve that by passing the subscription ID as parameter.
But I cannot found an Azure Powershell equivalent. The
Set-AzDiagnosticSetting does not allow pass the subscription ID. Instead, it accepts only the full resource ID.
When I try to use the following command, I get the error
Set-AzDiagnosticSetting: Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:NotFound, Reason phrase: Not Found:
$subsId = Get-AzContext | Select-Object Subscription
New-AzOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $rgName -Location $region -Sku "Standard"
$workspaceId = Get-AzOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $rgName | Select-Object ResourceId
$log = New-AzDiagnosticDetailSetting -Log -RetentionInDays 90 -Category Administrative -RetentionEnabled -Enabled
$setting = New-AzDiagnosticSetting -Name $dsName -WorkspaceId $workspaceId -TargetResourceId $subsId.Subscription.Id -Setting $log
Set-AzDiagnosticSetting -InputObject $setting
Have anyone already faced this issue? I appreciate any help.