msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Get-MgUser Filter AccountEnabled

Open YuriySamorodov opened this issue 5 years ago • 2 comments

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)

YuriySamorodov avatar Jan 24 '21 22:01 YuriySamorodov

You do not need to quote boolean values to use them in OData filters. Get-MgUser -Filter 'accountEnabled eq false' works just fine.

sergeyz7 avatar Jan 25 '21 15:01 sergeyz7

Thanks @sergeyz7

YuriySamorodov avatar Jan 25 '21 15:01 YuriySamorodov