Skip to content

Get-MgUser Filter AccountEnabled #515

@YuriySamorodov

Description

@YuriySamorodov

Get-MgUser -Filter "AccountEnabled eq 'True'" would give an Invalid filter clause error:

DEBUG

Get-MgUser -Filter "AccountEnabled ne 'False'" -Debug
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletProcessRecordAsyncStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: https://graph.microsoft.com/beta/users?$filter=AccountEnabled ne %27False%27
DEBUG: RequestCreated: https://graph.microsoft.com/beta/users?$filter=AccountEnabled ne %27False%27
DEBUG: HeaderParametersAdded: https://graph.microsoft.com/beta/users?$filter=AccountEnabled ne %27False%27
DEBUG: GET /beta/users?$filter=AccountEnabled%20ne%20%27False%27 HTTP/1.1
HTTP: graph.microsoft.com


DEBUG: BeforeCall:
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-MgUser_List: Invalid filter clause
DEBUG: GET https://graph.microsoft.com/beta/users?$filter=AccountEnabled%20ne%20%27False%27
HTTP/1.1 400 Bad Request
Cache-Control: private
request-id: f8d76fd8-e651-4740-ab9e-12450510c1cc
client-request-id: f8d76fd8-e651-4740-ab9e-12450510c1cc
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"SliceC","Ring":"5","ScaleUnit":"003","RoleInstance":"AGSFE_IN_24"}}
Strict-Transport-Security: max-age=31536000
Date: Sun, 24 Jan 2021 21:52:01 GMT
Content-Type: application/json
Content-Length: 285

I have also tried Search method to no avail:

Get-MgUser -Top 100 -Search "AccountEnabled:true" | measure

Count             : 100
Average           :
Sum               :
Maximum           :
Minimum           :
StandardDeviation :
Property         :

I understand I can get all users first selecting required properties and filter results afterwards

$users = Get-MgUser -All -Select id, DisplayName, UserPrincipalName, AccountEnabled
$users = $users | where { $_.AccountEnabled -eq $true }

However it would be very extremely handful to be able getting filtered results on using a single query.

[AB#7740](https://microsoftgraph.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_workitems/edit/7740)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions