CSC510219. Do not delete user profile.
User profile deletion is a important thing in the solution arch and you have to be seriosly motivated to do this. Generraly, SharePoint is synchronized with AD. If so and you delete user profile it would issued to unpredictable SharePoint behavoir.
UserProfileManager.RemoveUserProfile method (Guid)
UserProfileManager.RemoveUserProfile method (String)
Be aware that delete extra user profiles from SharePoint are in three steps:
- Delete the source accounts in AD.
- Re-sync the User Profiles. During this process, user profiles in SP but no longer in AD are marked for deletion. A full synchronization is not required for this marking to occur.
- Run My Site Cleanup Job in the Central Administration. This should (but for me doesn’t) purge all profiles marked for deletion from the system. It runs hourly by default.
- Instead deleteion use custom user profile property to mark as unnesesary for you.
- Consider to replace C# code with powershell script.
Delete all User Profiles in SharePoint 2010/2013 using PowerShell
Account Deletion and SharePoint 2010 User Profile Synchronization
Demystifying User Profile Deletion & Mysite Removal