Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

9 thoughts on “Delete SharePoint User Profile using PowerShell

  • March 5, 2020 at 5:15 PM

    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.

  • September 3, 2019 at 8:39 AM

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

    • September 4, 2019 at 8:41 AM

      Here you go:
      Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

      #Configuration Variables
      $SiteURL = “http://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

  • September 3, 2019 at 8:11 AM

    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?

  • July 3, 2019 at 2:15 PM

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

  • January 25, 2019 at 2:33 PM

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


Leave a Reply