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

Get-AzADGroup filter on groupTypes array returns "Invalid filter clause"

Open erwinkramer opened this issue 3 years ago • 2 comments

Description

groupTypes is a string collection: https://docs.microsoft.com/en-us/graph/api/resources/group?view=graph-rest-1.0

It should be able to filter on this as documented Returned by default. Supports $filter (eq, not)..

Trying this out with checking if groupTypes is an empty collection, or any other string comparison with eq fails with Invalid filter clause message.

Sample: Get-AzADGroup -Filter "() eq groupTypes" -consistencyLevel eventual -Debug

By the way, in Powershell return value it is specified as GroupType instead of GroupTypes (https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.powershell.cmdlets.resources.msgraph.models.apiv10.imicrosoftgraphgroup?view=az-ps-latest). Not sure if that matters.

Issue script & Debug output

Get-AzADGroup -Filter "() eq groupTypes"
 -consistencyLevel eventual -Debug
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: Client side pagination is enabled for this cmdlet
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /groups?$filter=%28%29%20eq%20groupTypes
DEBUG: RequestCreated: /v1.0/groups?$filter=%28%29%20eq%20groupTypes
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/groups?$filter=%28%29 eq groupTypes

Headers:
ConsistencyLevel              : eventual
x-ms-unique-id                : 4430
x-ms-client-request-id        : 746ebf0b-cfb4-4d7c-a988-2d1a9eca703d
CommandName                   : Az.MSGraph.internal\Get-AzAdGroup
FullCommandName               : Get-AzADGroup_List
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v8.3.0,PSVersion/v7.2.6,Az.MSGraph/6.2.0

Body:



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

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Strict-Transport-Security     : max-age=31536000
request-id                    : f60a5cb2-5fd5-4d70-8654-58f8bd26e7a0
client-request-id             : f60a5cb2-5fd5-4d70-8654-58f8bd26e7a0
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"000","RoleInstance":"AM1PEPF000105B9"}}
Date                          : Tue, 13 Sep 2022 15:50:06 GMT

Body:
{
  "error": {
    "code": "BadRequest",
    "message": "Invalid filter clause",
    "innerError": {
      "date": "2022-09-13T15:50:07",
      "request-id": "f60a5cb2-5fd5-4d70-8654-58f8bd26e7a0",
      "client-request-id": "f60a5cb2-5fd5-4d70-8654-58f8bd26e7a0"
    }
  }
}


DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzADGroup_List: C:\Users\x\Documents\PowerShell\Modules\Az.Resources\6.2.0\MSGraph.Autorest\custom\Get-AzADGroup.ps1:166
Line |
 166 |          Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid filter clause

DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.Resources:6.2.0; CommandName: Get-AzADGroup; PSVersion: 7.2.6; IsSuccess: False; Duration: 00:00:00.2057554; Exception: InternalException;

Environment data

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

Module versions

Get-Module Az*

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Script     2.10.0                Az.Accounts
Script     6.2.0                 Az.Resources

Error output

HistoryId: 2

Message        : [BadRequest] : Invalid filter clause
StackTrace     :
Exception      : System.Exception
InvocationInfo : {Get-AzADGroup_List}
Line           :         Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters

Position       : At C:\Users\NC2486\Documents\PowerShell\Modules\Az.Resources\6.2.0\MSGraph.Autorest\custom\Get-AzADGro
                 up.ps1:166 char:9
                 +         Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters
                 +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 2


The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

erwinkramer avatar Sep 13 '22 15:09 erwinkramer

@VeryEarly , please look into this question.

dingmeng-xue avatar Sep 14 '22 14:09 dingmeng-xue

@VeryEarly , please read comment of https://github.com/Azure/azure-powershell/issues/19485. We need to explain more about this parameter.

dingmeng-xue avatar Sep 15 '22 02:09 dingmeng-xue

@erwinkramer ,

please try filter "groupTypes/$count eq 0"

For more detail about filter query please refer to: https://learn.microsoft.com/en-us/graph/filter-query-parameter

VeryEarly avatar Sep 26 '22 02:09 VeryEarly

Doesn't seem to work, i tried 2 variants, cause i assume i have to escape the dollar sign.

With command

Get-AzADGroup -Filter "groupTypes/`$count eq 0" -consistencyLevel eventual -Debug

output:

DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: Client side pagination is enabled for this cmdlet
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /groups?$filter=groupTypes%2F%24count%20eq%200
DEBUG: RequestCreated: /v1.0/groups?$filter=groupTypes%2F%24count%20eq%200
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/groups?$filter=groupTypes%2F%24count eq 0

Headers:
ConsistencyLevel              : eventual
x-ms-unique-id                : 4
x-ms-client-request-id        : bfdb119e-744c-4d9f-8910-55167c14e6ac
CommandName                   : Az.MSGraph.internal\Get-AzAdGroup
FullCommandName               : Get-AzADGroup_List
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v0.0.0,PSVersion/v7.2.6,Az.MSGraph/6.2.0

Body:



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

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Transfer-Encoding             : chunked
Strict-Transport-Security     : max-age=31536000
request-id                    : 351f0395-cdc1-4eba-b04c-9b7e8f7ca567
client-request-id             : 351f0395-cdc1-4eba-b04c-9b7e8f7ca567
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"AM4PEPF00019DAE"}}
x-ms-resource-unit            : 1
Date                          : Mon, 26 Sep 2022 09:02:07 GMT

Body:
{
  "error": {
    "code": "Request_UnsupportedQuery",
    "message": "Unsupported or invalid query filter clause specified for property 'groupTypes' of resource 'Group'.",
    "innerError": {
      "date": "2022-09-26T09:02:08",
      "request-id": "351f0395-cdc1-4eba-b04c-9b7e8f7ca567",
      "client-request-id": "351f0395-cdc1-4eba-b04c-9b7e8f7ca567"
    }
  }
}


DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzADGroup_List: C:\Users\x\Documents\PowerShell\Modules\Az.Resources\6.2.0\MSGraph.Autorest\custom\Get-AzADGroup.ps1:166
Line |
 166 |          Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unsupported or invalid query filter clause specified for property 'groupTypes' of resource 'Group'.

DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.Resources:6.2.0; CommandName: Get-AzADGroup; PSVersion: 7.2.6; IsSuccess: False; Duration: 00:00:00.3054358; Exception: InternalException;

With command

Get-AzADGroup -Filter "groupTypes/$count eq 0" -consistencyLevel eventual -Debug

output:

DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: Client side pagination is enabled for this cmdlet
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /groups?$filter=groupTypes%2F%20eq%200
DEBUG: RequestCreated: /v1.0/groups?$filter=groupTypes%2F%20eq%200
DEBUG: HeaderParametersAdded:
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/groups?$filter=groupTypes%2F eq 0

Headers:
ConsistencyLevel              : eventual
x-ms-unique-id                : 6
x-ms-client-request-id        : 18358001-baa2-45e5-9ed7-1a9c7e0f81fe
CommandName                   : Az.MSGraph.internal\Get-AzAdGroup
FullCommandName               : Get-AzADGroup_List
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v0.0.0,PSVersion/v7.2.6,Az.MSGraph/6.2.0

Body:



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

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Strict-Transport-Security     : max-age=31536000
request-id                    : 621ecb07-d679-4cfe-ab9c-d0d821710e3e
client-request-id             : 621ecb07-d679-4cfe-ab9c-d0d821710e3e
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"AM4PEPF00019DAF"}}
Date                          : Mon, 26 Sep 2022 09:04:59 GMT

Body:
{
  "error": {
    "code": "BadRequest",
    "message": "Invalid filter clause",
    "innerError": {
      "date": "2022-09-26T09:05:00",
      "request-id": "621ecb07-d679-4cfe-ab9c-d0d821710e3e",
      "client-request-id": "621ecb07-d679-4cfe-ab9c-d0d821710e3e"
    }
  }
}


DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzADGroup_List: C:\Users\x\Documents\PowerShell\Modules\Az.Resources\6.2.0\MSGraph.Autorest\custom\Get-AzADGroup.ps1:166
Line |
 166 |          Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid filter clause

DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.Resources:6.2.0; CommandName: Get-AzADGroup; PSVersion: 7.2.6; IsSuccess: False; Duration: 00:00:00.1278927; Exception: InternalException;

erwinkramer avatar Sep 26 '22 09:09 erwinkramer

I think in order for this to work it has to expose the count parameter just like what happened with Get-AzADUser, also see https://github.com/Azure/azure-powershell/issues/16874 for when that was fixed. Maybe go through all Az modules with filter parameters and check if it's implemented? ...

erwinkramer avatar Sep 26 '22 09:09 erwinkramer

I think in order for this to work it has to expose the count parameter just like what happened with Get-AzADUser, also see #16874 for when that was fixed. Maybe go through all Az modules with filter parameters and check if it's implemented? ...

Hi @erwinkramer You're right, I have exposed "-Count" for Get-AzADApplication Get-AzADServiceprincipal Get-AzADGroup: #19651 , this will be available on 2022-10-12

VeryEarly avatar Sep 27 '22 06:09 VeryEarly

close issue as PR merged, please feel free to re-open if you have any questions.

VeryEarly avatar Sep 27 '22 08:09 VeryEarly

Issue still not resolved for me. Same issue as mentioned above

running following code

Import-Module -Name Az.Resources
Import-Module -Name Az.Accounts
Connect-AzAccount

Get-AzADGroup -filter "DisplayName -contains 'CAZ-S-RES'" -ConsistencyLevel eventual -debug

Console Output

DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing: 
DEBUG: CmdletProcessRecordStart: 
DEBUG: Client side pagination is enabled for this cmdlet
DEBUG: CmdletGetPipeline: 
DEBUG: CmdletBeforeAPICall: 
DEBUG: URLCreated: /groups?$filter=DisplayName%20-contains%20%27CAZ-S-RES%27
DEBUG: RequestCreated: /v1.0/groups?$filter=DisplayName%20-contains%20%27CAZ-S-RES%27
DEBUG: HeaderParametersAdded: 
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/groups?$filter=DisplayName -contains %27CAZ-S-RES%27

Headers:
ConsistencyLevel              : eventual
x-ms-unique-id                : 51,51
x-ms-client-request-id        : ed702e40-772b-4a35-8c2e-2c0977f1eaa9
CommandName                   : Az.MSGraph.internal\Get-AzAdGroup
FullCommandName               : Get-AzADGroup_List
ParameterSetName              : __AllParameterSets
User-Agent                    : AzurePowershell/v9.2.0,PSVersion/v7.3.1,Az.MSGraph/6.5.0

Body:



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

Status Code:
BadRequest

Headers:
    "message": "Invalid filter clause",
    "innerError": {
      "date": "2023-01-09T09:16:28",
      "request-id": "554a1886-9cbe-4204-889f-32dd9b388b95",
      "client-request-id": "554a1886-9cbe-4204-889f-32dd9b388b95"
    }
  }
}


DEBUG: ResponseCreated: 
DEBUG: BeforeResponseDispatch: 
Get-AzADGroup_List: C:\Users\oderm\OneDrive\Documents\PowerShell\Modules\Az.Resources\6.5.0\MSGraph.Autorest\custom\Get-AzADGroup.ps1:172:9
Line |
 172 |          Az.MSGraph.internal\Get-AzAdGroup @PSBoundParameters
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Invalid filter clause
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally: 
DEBUG: CmdletAfterAPICall: 
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd: 
DEBUG: CmdletProcessRecordEnd: 
DEBUG: AzureQoSEvent:  Module: Az.Resources:6.5.0; CommandName: Get-AzADGroup; PSVersion: 7.3.1; IsSuccess: False; Duration: 00:00:00.1244052; Exception: InternalException;

PS Version

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

PS Modules used

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.10.4                Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     6.5.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}

kathodion avatar Jan 09 '23 09:01 kathodion