In this blog, I would like to explain how to remove a user/users from all SharePoint Groups. Removing a user/users from all SharePoint Groups in a Site Collection would be a complex task to do manually.

This will remove the selected user/users from all SharePoint groups, libraries, lists and sub sites in the Site Collection.
Step 1: Open Powershell Window in your environment.

Step2: Copy and paste the code, given below. Run the code.
  1. $LoginName = "domain\loginname"
  2. $siteURL = "http://gowtham.sharepoint.com" #.
  3. Clear-Host
  4. $siteCount = 0
  5. [system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")
  6. $site = new-object microsoft.sharepoint.spsite($siteURL)
  7. $webApp = $site.webapplication
  8. $allSites = $webApp.sites
  9. foreach ($site in $allSites)
  10. {
  11. $web = $site.openweb()
  12. $web.SiteUsers.Remove($LoginName)
  13. $web.Dispose()
  14. $siteCount++
  15. }
  16. $site.dispose()
  17. write-host "User Deleed" $siteCount "Site Collections."