Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience 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.

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

    • 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
  • 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?

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

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


Leave a Reply

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