azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Get-AzureRmADApplication - Excpetion/Error message not useful

Open rajaprad opened this issue 9 years ago • 6 comments

Cmdlet(s)

Get-AzureRmADApplication

PowerShell Version

4.0

Module Version

OS Version

6.3.9600.17400

Description

There is no useful error messages from Get-AzureRmADApplication For example when i have insufficient permission on an directory, am getting the below errors,

Get-AzureRmADApplication : Exception of type 'System.Exception' was thrown. Only when i debug i come to know the actual error message,

DEBUG: Body: DEBUG: { DEBUG: "odata.error": { DEBUG: "code": "Authorization_RequestDenied", DEBUG: "message": { DEBUG: "lang": "en", DEBUG: "value": "Insufficient privileges to complete the operation." DEBUG: } DEBUG: } DEBUG: }

Debug Output

DEBUG: 6:44:03 PM - GetAzureADApplicationCommand begin processing with ParameterSet 'EmptyParameterSet'. DEBUG: 6:44:04 PM - using account id 'd48e5bad2a3'... DEBUG: [Common.Authentication]: Authenticating using Account: 'xxxxxbad2a3', environment: 'AzureCloud', tenant: 'xxxxxxx7fb1041c0' DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 07/03/2017 18:44:08: xxxxx-bd8cbfeaa700 - AcquireTokenHandlerBase: === Token Acquisition started: DEBUG: Authority: https://login.microsoftonline.com/xxxxxxxxxxx041c0/ DEBUG: Resource: https://graph.windows.net/ DEBUG: ClientId: xxxxxxxxxxxbad2a3 DEBUG: CacheType: Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache (2 items) DEBUG: Authentication Target: Client DEBUG:
DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 07/03/2017 18:44:08: xxxxx8cbfeaa700 - TokenCache: Looking up cache for a token... DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 07/03/2017 18:44:08:xxxxx3b-bd8cbfeaa700 - TokenCache: An item matching the requested resource was found in the cache DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 07/03/2017 18:44:08: xxxxxd8cbfeaa700 - TokenCache: 49.76567664 minutes left until token in cache expires DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 07/03/2017 18:44:08:xxxxxd8cbfeaa700 - TokenCache: A matching item (access token or refresh token or both) was found in the cache DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 07/03/2017 18:44:08: xxxxxxxd4dxxxab700 - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was retuned: DEBUG: Access Token Hash: xxxxx27ZvtEFebifj18= DEBUG: Refresh Token Hash: [No Refresh Token] DEBUG: Expiration Time: 07/03/2017 19:33:54 +00:00 DEBUG: User Hash: null DEBUG:
DEBUG: DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 07/03/2017 18:44:08: - TokenCache: Serializing token cache with 2 items. DEBUG: DEBUG: ============================ HTTP REQUEST ============================ DEBUG: DEBUG: HTTP Method: DEBUG: GET DEBUG: DEBUG: Absolute Uri: DEBUG: https://graph.windows.net/xxxxx1041c0/applications?api-version=1.6 DEBUG: DEBUG: Headers: DEBUG: x-ms-client-request-id : xxxx6e-ccbf1b9b10d6 DEBUG: accept-language : en-US DEBUG: DEBUG: Body: DEBUG: DEBUG: DEBUG: DEBUG: ============================ HTTP RESPONSE ============================ DEBUG: DEBUG: Status Code: DEBUG: Forbidden DEBUG: DEBUG: Headers: DEBUG: Pragma : no-cache DEBUG: ocp-aad-diagnostics-server-name: 2+oocPXXxxxxxGsbmNGmU= DEBUG: request-id : xxxxx16052d250 DEBUG: client-request-id : xxxxxe20d5e4ff6 DEBUG: x-ms-dirapi-data-contract-version: 1.6 DEBUG: ocp-aad-session-key : CDc3i1PftsBUdZmPVIZZ1xxxxi4MIhPEwM8yOAKFAxxvRTK0tosw-itQRo1e8ejesgaZw2uXM5T-IbcrxxO.4zMWIzu-Spa7kz6-lxl5xxsJ1MNSYgGw3Q KFh-tM DEBUG: X-Content-Type-Options : nosniff DEBUG: DataServiceVersion : 3.0; DEBUG: Strict-Transport-Security : max-age=31536000; includeSubDomains DEBUG: Access-Control-Allow-Origin : * DEBUG: Duration : 1964457 DEBUG: Cache-Control : no-cache DEBUG: Server : Microsoft-IIS/8.5 DEBUG: X-AspNet-Version : 4.0.30319 DEBUG: X-Powered-By : ASP.NET,ASP.NET DEBUG: Date : Mon, 03 Jul 2017 18:44:10 GMT DEBUG: DEBUG: Body: DEBUG: { DEBUG: "odata.error": { DEBUG: "code": "Authorization_RequestDenied", DEBUG: "message": { DEBUG: "lang": "en", DEBUG: "value": "Insufficient privileges to complete the operation." DEBUG: } DEBUG: } DEBUG: } DEBUG: DEBUG: DEBUG: Caught exception, type: Microsoft.Azure.Graph.RBAC.Models.GraphErrorException DEBUG: Received exception from graph. ErrorCode: , Message: Get-AzureRmADApplication : Exception of type 'System.Exception' was thrown. At line:1 char:1

  • Get-AzureRmADApplication -debug
  •   + CategoryInfo          : InvalidOperation: (:) [Get-AzureRmADApplication], Exception
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.GetAzureADApplicationCommand
    
    

DEBUG: 6:44:11 PM - GetAzureADApplicationCommand end processing. DEBUG: 6:44:11 PM - GetAzureADApplicationCommand end processing.

Script/Steps for Reproduction

Get-AzureRmADApplication without having permissions on the directory.

rajaprad avatar Jul 03 '17 20:07 rajaprad

@rajaprad thanks for the issue. Moving forward, if you would ever like to get more information on an error that you receive, we suggest running the cmdlet Resolve-AzureRmError, and that will get you more detailed information after the exception occurs without having to re-run the cmdlet.

cormacpayne avatar Jul 07 '17 18:07 cormacpayne

Similar issue, the Exception is not populated :-( :-( Took some time and Format-Custom to find out.

Now trying Resolve-AzureRMError.

Calling from PowerShell Console Host, this cmdlet is available. However, inside the ISE, loading exactly the same module , VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\azurerm.profile\3.1.0\azurerm.profile.psd1', the Resolve-AzureRMError cmdlet is not loaded or found. Tried Import-Module -verbose -force.

juancrl avatar Jul 10 '17 11:07 juancrl

@juancrl Have you loaded a different version of profile in ISE - all shells in ISE are in the same PowerShell session, so multiple versions of binary cmdlets cannot be loaded.

Meanwhile, in this case, having a better error message that points twoard how to solve the issue would be beneficial. Assigning to the Autmation team for triage

markcowl avatar Aug 08 '17 19:08 markcowl

@darshanhs90 The ask here is to detect the insufficient privileges error that comes from graph API calls and suggest how the user can fix this issue in the error we throw.

markcowl avatar Aug 08 '17 19:08 markcowl

Fixed the loading (probably something corrupt in my environment), now Resolve-AzureRMError is available.

However, it just displays the exception data, which already was available in try/catch.

Launching the previous cmdlet with -DEBUG does provide the needed troubleshooting info, but it must be explicitly redirected away from screen (too verbose). It would be nice if Resolve-AzureRMError could provide this functionality.

juancrl avatar Aug 08 '17 19:08 juancrl

Closing this as the issue is fixed in the powershell release 4.4.0

darshanhs90 avatar Sep 26 '17 18:09 darshanhs90