Removing A User/Users From All Sharepoint Groups In A Site Collection

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.   
  4. Clear-Host  
  5. $siteCount = 0  
  6. [system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")  
  7. $site = new-object microsoft.sharepoint.spsite($siteURL)  
  8. $webApp = $site.webapplication  
  9. $allSites = $webApp.sites  
  10. foreach ($site in $allSites)  
  11. {  
  12.   
  13.     $web = $site.openweb()  
  14.     $web.SiteUsers.Remove($LoginName)  
  15.     $web.Dispose()  
  16.     $siteCount++  
  17. }  
  18. $site.dispose()  
  19. write-host "User Deleed" $siteCount "Site Collections."  
Ebook Download
View all
Learn
View all