SharePoint 2013 : ADImport is not cleaning up User Profiles in SharePoint whose AD Accounts are disabled .

 

We recently came across cases where  Profiles of Disabled users in AD are not getting deleted from SharePoint User Profile Service Application when using ADImport. Read further to get more details on the issue & the workarounds .

Behavior: When using “SharePoint Active Directory Import” for the Synchronization Options in SharePoint 2013 , the users who are disabled  in Active Directory are not getting removed from SharePoint post a Full/Incremental Import . .  A deeper look into this reveals that account is not marked as deleted ( bdeleted=1 flag in UserProfile_full Table of the Profile Database of the UPA) . This behavior is seen even though we check the option to “Filter out disabled users” while creating the Sync Connection.

clip_image001

Note : The behavior is continued to be seen even when a Custom Filter is defined in LDAP syntax in the box provided .  Also If the user is not disabled & moved to another OU which is not selected to be Sync , similar behavior is observed.

Observation:

Since we are not using FIM for synchronization, there is nothing to look into Sync DB. Everything happens within Profile DB. Full import will detect the user is not getting imported and marks the field ‘IsImported’ to 0 on DNLookup table in Profile DB for the affected user. However it still does not set bdeleted to 1 in UserProfile_Full table which is needed for MySiteCleanUp Job to delete the profile and finally Personal Site.

Following is the sample query to check all the users which exist in Profile DB with the Status , ‘IsImported’ to 0 , You can match this list with your disabled users in AD to Confirm .

SELECT A.RecordID,A.NTName, A.bDeleted, B.IsImported

FROM [UserProfile_Full] A (nolock)

inner join [DNLookup] B (nolock)

on A.RecordID = B.RecordId

where b.IsImported =0

Note : It is not recommended to Query any Sharepoint databases or to make changes other than ones described at https://support.microsoft.com/kb/841057 .

Workaround:

The “SharePoint Active Directory Import” does not mark the profile to be deleted either with incremental or Full Import when they are disabled and only way to remove the obsolete users is as mentioned HERE .

1 Run Full Import

2 Post that run Use SharePoint Management Shell to Run following

a) $upa = Get-SPServiceApplication -id <Identity of User Profile Service Application>

b) Set-SPProfileServiceApplication -Identity $upa -GetNonImportedObjects $true

Note: Review the output of this command before proceeding with the next step. The objects retrieved using this command will be marked for deletion once the next command is executed.

C) Set-SPProfileServiceApplication -Identity $upa -PurgeNonImportedObjects $true

At this point of writing this blog (31-Mar-2014), this is known behavior with   work around as tested against SharePoint 2013 SP1 Build .

Note: The Deletion of an account in AD is handled as expected & profile in SharePoint Profile Database is marked as deleted ( bdeleted=1) & eventually cleared by Mysite Cleanup job .

 

POST BY: Satheesh Palanisamy [MSFT]