O365 – CSOM Check if a user does not exist in your tenant anymore

I had a situation where I needed to make sure if a user does not exist anymore in the O365 system. I had to use CSOM for this solution and no matter how I tried I could not get any indication that a user has been deleted from the system.

I tried the IsActive field and Deleted field of an user object but no luck. No matter what I did even if the user was deleted and the expiration date of 30 days expired the user was still active.

My solution was that I checked to see if CSOM could retrieve a user profile data. If no data could be retrieved then this is an indication that the user profile has been deleted, hence the user has been deleted from the system. That is it. I used a field like account name since I know it must exist for all users.

There may be a “proper” solution for this but I just could not find one no matter how hard I tried(or maybe I just looked in the wrong place 🙂 ). Anyway see my previous post on how to get user profile information on how to do this workaround:

https://lionadi.wordpress.com/2015/09/16/o365-csom-getting-user-profile-information-without-possible-errors/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s