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

Get-AzADUser with advanced queries not working

Open erwinkramer opened this issue 3 years ago • 12 comments

Description

If i understand correctly, the following advanced query should work because i set consistencyLevel eventual:

Get-AzADUser -select 'Department' -AppendSelected -consistencyLevel eventual -Filter "Department ne null"

Documentation: https://docs.microsoft.com/en-us/graph/aad-advanced-queries#support-for-filter-on-properties-of-azure-ad-directory-objects

Issue script & Debug output

Get-AzADUser -select 'Department' -AppendSelected -consistencyLevel eventual -Filter "Department ne null"
Get-AzADUser_List:....\PowerShell\Modules\Az.Resources\5.2.0\MSGraph.Autorest\custom\Get-AzADUser.ps1:210
Line |
 210 |          Az.MSGraph.internal\Get-AzADUser @PSBoundParameters
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unsupported property filter clause operator 'NotEqualsMatch'.

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
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

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.7.1                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script     2.3.1                 Az.ApiManagement                    {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion…}
Script     5.2.0                 Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}

Error output

Message        : [Request_UnsupportedQuery] : Unsupported property filter clause operator 'NotEqualsMatch'.
StackTrace     :
Exception      : System.Exception
InvocationInfo : {Get-AzADUser_List}
Line           :         Az.MSGraph.internal\Get-AzADUser @PSBoundParameters

Position       : At C:\Users\ekramer\Documents\PowerShell\Modules\Az.Resources\5.2.0\MSGraph.Autorest\custom\Get-AzADUser.ps1:210 char:9
                 +         Az.MSGraph.internal\Get-AzADUser @PSBoundParameters
                 +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 127

erwinkramer avatar Jan 19 '22 13:01 erwinkramer

It seems a service bug. Its behavior is different from documentation. I use the example on doc and send request to service directly

# Works
GET https://graph.microsoft.com/v1.0/users?companyName ne null

# Doesn't work
GET https://graph.microsoft.com/v1.0/users?$filter=companyName ne null

#works
https://graph.microsoft.com/v1.0/users?$filters=companyName ne null

I seems filters support it but API spec doesn't mention that query parameter https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/2d2ce81e3f093a9c6e8642beac37c868017b9c63/openApiDocs/v1.0/Users.yml#L28

dingmeng-xue avatar Jan 19 '22 13:01 dingmeng-xue

@dingmeng-xue the documentation specifies that the count parameter should be included too, maybe that's what is missing, it should be added by default when you call the Az.Resources module with a filter like that.

these advanced query capabilities are not available by default but, the requestor must also set the ConsistencyLevel header to eventual and, with the exception of $search, use the $count query parameter. The ConsistencyLevel header and $count are referred to as advanced query parameters.

https://docs.microsoft.com/en-us/graph/aad-advanced-queries

erwinkramer avatar Jan 19 '22 14:01 erwinkramer

It's not the reason. You can try it via website https://developer.microsoft.com/en-us/graph/graph-explorer

dingmeng-xue avatar Jan 19 '22 14:01 dingmeng-xue

It absolutely requires the $count parameter but there's no way in the current parameters to do this short of a convoluted httppipelineprepend. In the graph SDK there is a -countvariable parameter that sets $count and returns the count to that set variable, these Az commands should replicate that behavior.

image

JustinGrote avatar Feb 01 '22 17:02 JustinGrote

@JustinGrote , According to API spec of MSGraph, count is not required parameter.

When I tried GET https://graph.microsoft.com/v1.0/users?$filter=Department%20ne%20null&$count=true, I got

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported property filter clause operator 'NotEqualsMatch'.",
        "innerError": {......}
    }
}

dingmeng-xue avatar Feb 03 '22 12:02 dingmeng-xue

@JustinGrote , According to API spec of MSGraph, count is not required parameter.

When I tried GET https://graph.microsoft.com/v1.0/users?$filter=Department%20ne%20null&$count=true, I got

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported property filter clause operator 'NotEqualsMatch'.",
        "innerError": {......}
    }
}

Your query is not the same as my query. You did a ne filter, not an eq filter, you did it on department not company, and it is also not clear if you specified ConsistencyLevel eventual header. You need both the header and count for advanced queries

JustinGrote avatar Feb 03 '22 15:02 JustinGrote

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

msftbot[bot] avatar Feb 10 '22 20:02 msftbot[bot]

Still an issue.

JustinGrote avatar Feb 10 '22 20:02 JustinGrote

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

msftbot[bot] avatar Feb 18 '22 02:02 msftbot[bot]

@dingmeng-xue still an issue.

JustinGrote avatar Feb 18 '22 02:02 JustinGrote

I'm also running to same issue with Get-AzADUser cmdlet. Any estimates on fix timeline?

Mrkokoo avatar Aug 02 '22 09:08 Mrkokoo

We will expose parameter: "Count" in 2022-09-06 release

VeryEarly avatar Aug 03 '22 02:08 VeryEarly

Thanks, this works now: Get-AzADUser -select 'Department' -AppendSelected -consistencyLevel eventual -Filter "Department ne null" -Count

erwinkramer avatar Sep 26 '22 09:09 erwinkramer