Sitecore EXM
Sometimes we might need to clear old users / specific domain users. We can do this job from the Sitecore User Manager and remove them one by one. But if the number of users is more then it will be a tedious job. We can do it in bulk using a SQL script or a Powershell script to remove Sitecore users.

PowerShell script should be the first choice:
Get-User -Filter * | Where-Object {$_.Profile.Email -like "*@gmail.com"} | Remove-User

SQL script as the second option:

Select UserId Into #TempUserList
From [www-s9-uat7-xp1_Core].[dbo].[aspnet_Membership]
Where Email Like '%@gmail.com'

Delete From [www-s9-uat7-xp1_Core].[dbo].[aspnet_UsersInRoles]
Where UserId in (Select UserId From #TempUserList)

Delete From [www-s9-uat7-xp1_Core].[dbo].[aspnet_Membership]
Where UserId in (Select UserId From #TempUserList)

Delete From [www-s9-uat7-xp1_Core].[dbo].[aspnet_PersonalizationPerUser]
Where UserId in (Select UserId From #TempUserList)

Delete From [www-s9-uat7-xp1_Core].[dbo].[aspnet_Profile]
Where UserId in (Select UserId From #TempUserList)

Delete FROM [www-s9-uat7-xp1_Core].[dbo].[aspnet_Users]
Where UserId in (Select UserId From #TempUserList)
Previous post Filter user by domain in Sitecore User Manager
Sitecore EXM Next post Sitecore 9 Experience profile common error

Leave a Reply

Your email address will not be published.