Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

9 thoughts on “How to Delete a SharePoint User Profile using PowerShell?

  • How to remove AD disabled/deactivated users from user profile service application. I got to delete these. I am looking for power shell script which can delete disabled users from user profile application.

    Reply
  • Please can you tell me where the domain qualifier goes within the section? thanks

    Reply
    • Here you go:

      Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
       
      #Configuration Variables
      $SiteURL = "https://your-sharepoint-site-url"
      $DomainPrefix = "Crescent"
       
      #Get Objects
      $ServiceContext  = Get-SPServiceContext -site $SiteURL
      $UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
       
      #Ger all User Profiles of a domain
      $UserProfiles = $UserProfileManager.GetEnumerator()
        
      # Loop through user profile
      Foreach ($Profile in $UserProfiles) 
      {
          write-host Removing User Profile: $Profile["AccountName"] 
           
          #Remove User Profile
          $UserProfileManager.RemoveUserProfile($profile["AccountName"])
      }
      
      Reply
  • I am new to powershell – I managed to use your code to delete individual user accounts thank you (they deleted even though I got an error message) BUT when you add the qualifying lines about just finding those from a specific domain can you please tell me where in the entire set of code they actually need to go?
    Thanks

    Reply
  • great script! I want to add a minor correction in the removal part should be $UserProfileManager.RemoveUserProfile instead of $ProfileManager.RemoveUserProfile

    Reply
  • How about for SharePoint Online? 🙂 Cannot find the right way to do this.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *