Posts

Showing posts from August, 2018

Automate Removal of Orphan Users from SharePoint Online Using CSOM

If you had just migrated to SharePoint Online, one of the few things you will notice is that removing  a user from Azure Active Directory (AAD) does not automatically remove the user from SharePoint sites. This is by design, it is not a bug. This is to ensure that documents uploaded or created by those users are kept with their names in "Created By" field. So after removing them from AAD you have to go to each site the users have access to and manually remove them. But this poses a huge maintenance problem as you can't possibly keep up with this repetitive task, and even  knowing all the sites the user has access to poses a greater challenge. The best solution is to write a daemon application to handle such task. If you already find yourself in this situation and need a solution, just copy and paste the code below in a console application: We need to loop through a list of all AAD users and compare them with users in our SharePoint site collections. To get this list,