Search code examples
powershellgraphmicrosoft-graph-api

Graph Api multifiltering to get user with last log in last 30 days


i'm trying to build a request with graph api to get all user enabled not logged in the last 30days. With:

$URL = "https://graph.microsoft.com/v1.0/users?`$filter=signInActivity/lastSignInDateTime le 2023-12-21T00:00:00Z"

i'm able to get all user not logged before 2023-12-21. I need to filter further the list to exclude user with specific field but it is not working:

companyName ne 'mycompany' and department ne 'mydepartment' and accountEnabled eq true

$URL = "https://graph.microsoft.com/v1.0/users?`$filter=signInActivity/lastSignInDateTime le 2023-12-21T00:00:00Z and companyName ne 'mycompany' and department ne 'mydepartment' and accountEnabled eq true&`$select=userPrincipalName,signInActivity"

With follow url i can get all user enabled excluding my company and department.

$URL = "https://graph.microsoft.com/v1.0/users?`$count=true&`$top=999&ConsistencyLevel=eventual&`$filter=companyName ne 'mycompany' and department ne 'mydepartment' and accountEnabled eq true&`$select=userPrincipalName,signInActivity"

but not user not logged in the last 30 days. I tried to add:

$URL = "https://graph.microsoft.com/v1.0/users?`$count=true&`$top=999&ConsistencyLevel=eventual&`$filter=companyName ne 'mycompany' and department ne 'mydepartment' and accountEnabled eq true&`$select=userPrincipalName,signInActivity/lastSignInDateTime le 2023-12-21T00:00:00Z"

but it is not working. There is a way to fix it?

Thankss


Solution

  • As mentioned in the doc, when filtering by signInActivity, it can't be combined with any other filterable properties.

    Only solution for now is to apply filter for companyName, department and accountEnabled on the client.