SharePoint Onpremise UPA : Deleted disabled users/profiles

Kevin Nguyen 101 Reputation points
2022-01-21T10:09:57.5+00:00

Hi Guys,

I'm struggling with the User Profil App service.

What I want to do is to delete the disabled users from AD and not show them in people search in my farm.

It's kinda working.

Here's my steps :

  • From PowerShell :

Set-SPProfileApplicationService $service -PurgeNonImportedObject $true

  • Central Admin :

    Set the import filter (&(objectClass=user)(!userAccountControl=2))
    Start a full profil sync
    Start MySite Cleanup Job
    Start full profile crawl

These steps deleted all disabled users from people search but the number of profil count didn't change.

I tried to reverse my steps to import all users (even disabled) to confirm/retry the scenario before doing it on prod.

However I can't reimport "already" deleted profiles...

Do you have any ideas ?

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,227 questions
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,456 Reputation points
    2022-01-25T09:06:42.167+00:00

    Hi @Kevin Nguyen
    Generally SharePoint user profiles will get deleted when any of the below incident happens:

    1. User account is deleted in Active Directory
    2. Account is disabled
    3. User Profile Service Application Connection is changed or recreated
    4. Account is recreated in AD or moved out of an OU which is not part of SharePoint User Profile sync connection

    However, sometimes you may have to delete SharePoint user profiles manually.

    You could use powershell to delete user profile:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
       
    #Configuration Variables  
    $SiteURL = "http://mypage.crescent.com"  
    $AccountName="Crescent\Sherif"  
       
    #Get Objects  
    $ServiceContext  = Get-SPServiceContext -site $SiteURL  
    $UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)  
       
    #Get the User Profile  
    $UserProfile = $UserProfileManager.GetUserProfile($AccountName)  
       
    #remove user profile  
    $UserProfileManager.RemoveUserProfile($AccountName);   
      
    ********************************************  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful