Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$Count fails on Get-MgOauth2PermissionGrant due to lack of consistencyLevel header option #2548

Closed
erhallMSFT opened this issue Jan 26, 2024 · 2 comments

Comments

@erhallMSFT
Copy link

Describe the bug
Get-MgOauth2PermissionGrant does not properly return a count of objects. This is because $count requires a consistencyLevel=eventual header, but the command does not include consistency level as an available parameter. Note that this also affects get-mgoauth2permissiongrantcount for the same reason.

To Reproduce
Steps to reproduce the behavior:

  1. Execute Get-MgOauth2PermissionGrant -CountVariable Foo
  2. Or execute Get-MgOauth2PermissionGrantCount
  3. Option 1 returns no error, Option 2 returns an error:
Get-MgOauth2PermissionGrantCount_Get: Raw count (/$count) is not supported because the 'ConsistencyLevel:eventual' header is missing. Refer to https://aka.ms/graph-docs/advanced-queries for more information

Following the syntax of other commands, Get-MgOauth2PermissionGrant -CountVariable Foo -ConsistencyLevel eventual returns:

Get-MgOauth2PermissionGrant: A parameter cannot be found that matches parameter name 'ConsistencyLevel'.

Expected behavior

$Foo is populated with the count of Oauth2PermissionGrant Objects

Debug Output

PS C:\Users\erhall> get-mgOauth2PermissionGrant -CountVariable foo -debug
DEBUG: [CmdletBeginProcessing]: - Get-MgOauth2PermissionGrant begin processing with parameterSet 'List'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: <REDACTED>
DEBUG: [Authentication]: - Scopes: [<REDACTED>, Directory.ReadWrite.All, <REDACTED>].
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/oauth2PermissionGrants?$count=true

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631; en-US),PowerShell/7.4.0
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell/2.12.0
client-request-id             : e9379e91-0f34-47f3-88a2-6e19c3ddcae8

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Date                          : Fri, 26 Jan 2024 18:18:44 GMT
Transfer-Encoding             : chunked
Connection                    : keep-alive
Cache-Control                 : no-cache
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 0d739e49-3c7b-49fe-8134-6245c9547ff7
client-request-id             : e9379e91-0f34-47f3-88a2-6e19c3ddcae8
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"West US 2","Slice":"E","Ring":"1","ScaleUnit":"002","RoleInstance":"MWH0EPF00032D53"}}
x-ms-resource-unit            : 2
OData-Version                 : 4.0
X-Cache                       : CONFIG_NOCACHE

Body:
{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#oauth2PermissionGrants",
  "@odata.nextLink": "https://graph.microsoft.com/v1.0/oauth2PermissionGrants?$count=true&$skiptoken=<REDACTED>",
  "value": [<DATA REDACTED>

Run the problematic command with -Debug and paste the resulting debug stream below.
⚠ ATTENTION: Be sure to remove any sensitive information that may be in the logs.

Module Version

Please run Get-Module Microsoft.Graph* after cmdlet execution and paste the output below.
If a module cannot be installed or imported, please run Get-Module -ListAvailable and paste the output.

PS C:\Users\> get-module microsoft.graph*

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.12.0                Microsoft.Graph.Applications        {Add-MgApplicationKey, Add-MgApplicationPassword, Add-MgServicePrincipalKey, Add-MgServicePrin… 
Script     2.12.0                Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext…}
Script     2.12.0                Microsoft.Graph.Beta.Identity.Sign… {Confirm-MgBetaInformationProtectionSignature, Confirm-MgBetaRiskyServicePrincipalCompromised,… 
Script     2.12.0                Microsoft.Graph.Identity.SignIns    {Confirm-MgRiskyServicePrincipalCompromised, Confirm-MgRiskyUserCompromised, Get-MgDataPolicyO… 
Script     2.12.0                Microsoft.Graph.Users               {Get-MgUser, Get-MgUserCount, Get-MgUserCreatedObject, Get-MgUserCreatedObjectAsServicePrincip… 

Environment Data

Please run $PSVersionTable and paste the output below. If running the Docker container image, indicate the tag of the image used and the version of Docker engine.

PS C:\Users\erhall> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

@erhallMSFT erhallMSFT changed the title Count fails on Get-MgOauth2PermissionGrant due to lack of consistencyLevel header option $Count fails on Get-MgOauth2PermissionGrant due to lack of consistencyLevel header option Jan 26, 2024
@timayabi2020
Copy link
Contributor

Hi @erhallMSFT with the current version(2.15.0), one is able to provide additional headers via the -Headers parameter. That is Get-MgOauth2PermissionGrantCount -Headers @{ 'ConsistencyLevel' = 'eventual' }. However, for this case it returns a different error stating that the query option $count is not supported. I am also unable to get the related api reference doc here.

image

For API related issues/questions we are not best placed to give an answer. Kindly raise an issue here https://developer.microsoft.com/en-us/graph/support so that the API owner can respond to it.

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants