Azure / Azure/azure-powershell
Get-AzDiagnosticSetting does not return the diagnostic setting of an Automation account
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
# Steps for reproducing
- Create an Azure automation account
- Create an Log Analytics workspace
- Configure the Diagnostic settings of the Automation account so that it writes to the Log Analytic workspace created above
- Run the PowerShell command Get-AzDiagnosticSetting (with and without the -name parameter)


# PowerShell command to retrieve the diagnostic setting
```
Get-AzDiagnosticSetting -ResourceId "/subscriptions/635a2074-cc31-43ac-bebe-2bcd67e1abfe/resourceGroups/rg-demo-automation-account/providers/Microsoft.Automation/automationAccounts/sauautomationaccount001" -debug
```
# Did I try using the Azure CLI?
Yes. It comes up empty
```
az monitor diagnostic-settings list --resource "/subscriptions/635a2074-cc31-43ac-bebe-2bcd67e1abfe/resourceGroups/rg-demo-automation-account/providers/Microsoft.Automation/automationAccounts/sauautomationaccount001"
```
```
{
"value": []
}
`
``
### Issue script & Debug output
```PowerShell
Get-AzDiagnosticSetting -ResourceId "/subscriptions/635a2074-cc31-43ac-bebe-2bcd67e1abfe/resourceGroups/rg-demo-automation-account/providers/Microsoft.Automation/automationAccounts/sauautomationaccount001" -debug
WARNING: 15:10:23 - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.
DEBUG: [Common.Authentication]: Authenticating using Account: 'saurabh_dasgupta@hotmail.com', environment: 'AzureCloud', tenant: 'e66fc46b-2666-4ea3-984d-bb30c06f2c75'
DEBUG: 15:10:23 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'e66fc46b-2666-4ea3-984d-bb30c06f2c75', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'saurabh_dasgupta@hotmail.com'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23] Found 1 cache accounts and 0 broker accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23] Returning 1 accounts
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] MSAL MSAL.NetCore with assembly version '4.30.1.0'. CorrelationId(7dbe9031-3091-425c-9a6b-82f9b5b0b706)
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] === AcquireTokenSilent Parameters ===
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] LoginHint provided: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Account provided: True
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] ForceRefresh: False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 7dbe9031-3091-425c-9a6b-82f9b5b0b706
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] === Token Acquisition (SilentRequest) started:
Authority Host: login.microsoftonline.com
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Azure region was not configured or could not be discovered. Not using a regional authority.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Access token is not expired. Returning the found cache entry. [Current time (05/29/2022 14:10:23) - Expiration Time (05/29/2022 14:55:15 +00:00) - Extended Expiration Time (05/29/2022 14:55:15 +00:00)]
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Returning access token found in cache. RefreshOn exists ? False
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] Fetched access token from host login.microsoftonline.com.
DEBUG: (False) MSAL 4.30.1.0 MSAL.NetCore Microsoft Windows 10.0.19044 [05/29/2022 14:10:23 - ] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 05/29/2022 14:55:15 +00:00 and Scopes https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ExpiresOn: 2022-05-29T14:55:15.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'e66fc46b-2666-4ea3-984d-bb30c06f2c75', UserId: 'saurabh_dasgupta@hotmail.com'
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com//subscriptions/635a2074-cc31-43ac-bebe-2bcd67e1abfe/resourceGroups/rg-demo-automation-account/providers/Microsoft.Automation/automationAccounts/sauautomationaccount001/providers/Microsoft.Insights/diagnosticSettings?api-version=2017-05-01-preview
Headers:
x-ms-client-request-id : 70c82386-915b-4cd0-b4c6-f428bdbe0349
Accept-Language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
OK
Headers:
Cache-Control : no-cache
Pragma : no-cache
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-request-id : 3130c77f-2293-459a-95ef-2ff0cefd65cd
Server : Microsoft-IIS/10.0
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-correlation-request-id : e5e017b3-8857-4adf-8f9d-e0e9f1224b5d
x-ms-routing-request-id : UKSOUTH:20220529T141023Z:e5e017b3-8857-4adf-8f9d-e0e9f1224b5d
X-Content-Type-Options : nosniff
Date : Sun, 29 May 2022 14:10:22 GMT
Body:
{
"value": []
}
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.7.5 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script 3.0.1 Az.Monitor {Add-AzAutoscaleSetting, Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2…}
Script 5.3.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
```
### Error output
```PowerShell
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.
HistoryId: 9
Message : Exception type: ErrorResponseException, Message: Microsoft.Azure.Management.Monitor.Models.ErrorResponseException: Operation returned an invalid status code 'NotFound'
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.GetWithHttpMessagesAsync(String resourceUri, String name, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.GetAsync(IDiagnosticSettingsOperations operations, String resourceUri, String name, CancellationToken
cancellationToken)
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.Get(IDiagnosticSettingsOperations operations, String resourceUri, String name)
at Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand.ProcessRecordInternal()
at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet(), Code: Null, Status code:Null, Reason phrase: Null
StackTrace : at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {Get-AzDiagnosticSetting}
Line : Get-AzDiagnosticSetting -ResourceId $resource.id -Name my-diganostic-001 -debug
Position : At line:1 char:1
+ Get-AzDiagnosticSetting -ResourceId $resource.id -Name my-diganostic- …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 9
Message : Operation returned an invalid status code 'NotFound'
StackTrace : at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.GetWithHttpMessagesAsync(String resourceUri, String name, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.GetAsync(IDiagnosticSettingsOperations operations, String resourceUri, String name, CancellationToken
cancellationToken)
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.Get(IDiagnosticSettingsOperations operations, String resourceUri, String name)
at Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand.ProcessRecordInternal()
at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException
InvocationInfo : {Get-AzDiagnosticSetting}
Line : Get-AzDiagnosticSetting -ResourceId $resource.id -Name my-diganostic-001 -debug
Position : At line:1 char:1
+ Get-AzDiagnosticSetting -ResourceId $resource.id -Name my-diganostic- …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 9
```
Contributor guide
Assessment
This issue has not been assessed yet.