My requirement is to fetch permissions granted to Azure ad application from powershell. I have an application with few delegated permissions like this:
I found Get-AzureADServicePrincipalOAuth2PermissionGrant
command to achieve my scenario.
But I am facing this error, when I ran the above command:
Get-AzureADServicePrincipalOAuth2PermissionGrant : Error occurred while executing GetServicePrincipalOAuth2PermissionGrants
Code: Request_ResourceNotFound
Message: Resource 'XXXXXXXX does not exist or one of its queried reference-property objects are not present.
RequestId: d0ed46b9-e8ea-47c0-b575-10ba67863ac6
DateTimeStamp: Wed, 10 Aug 2022 05:59:54 GMT
HttpStatusCode: NotFound
HttpStatusDescription: Not Found
HttpResponseStatus: Completed
At line:1 char:1
+ Get-AzureADServicePrincipalOAuth2PermissionGrant -ObjectId XXXXX...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureADServ...PermissionGrant], ApiException
+ FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetServicePrincipalOAuth2PermissionGrants
I have given the correct ObjectId of the application and I have admin role.
Help me with suggestions on how to avoid this error?