Need to gather detail on deleted AAD user objects, and Graph once again comes to the rescue.

Really happy with how well these APIs work, but real kudos goes to the docs:

Though the API is well documented there was a slight twist that took me a few minutes to figure out.$filter=endswith(mail,'')&$count=true
    "@odata.context": "$metadata#users",
    "@odata.count": 2,
    "value": [
            "displayName": "Nino Schurter",
            "givenName": "Nino",
            "mail": "",
            "officeLocation": "Van Life"
            "displayName": "Jenny Risveds",
            "givenName": "Jenny",
            "mail": "",
            "surname": "Risveds"

In my case, two issues prevented this from working:

  • leaving out $count from the query string
  • leaving out the ConsistencyLevel header with a value of ‘eventual’

The sample above worked great, here is what I ended up with to:

  • return only users
  • return only items deleted in the past couple of days (we delete a lot of users)
  • return the count of deleted users
  • return just a few attributes for each user$filter=endswith(mail,'')+and+deletedDateTime+ge+2022-08-20T00:00:00Z&$count=true&$select=mail,mailnickname,employeeid,onPremisesImmutableId