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.
- $LoginName = "domain\loginname"
- $siteURL = "http://gowtham.sharepoint.com" #.
-
- Clear-Host
- $siteCount = 0
- [system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")
- $site = new-object microsoft.sharepoint.spsite($siteURL)
- $webApp = $site.webapplication
- $allSites = $webApp.sites
- foreach ($site in $allSites)
- {
-
- $web = $site.openweb()
- $web.SiteUsers.Remove($LoginName)
- $web.Dispose()
- $siteCount++
- }
- $site.dispose()
- write-host "User Deleed" $siteCount "Site Collections."