SharePoint: How to delete Groups in every Site in a Site Collections - Fabian Neve

About SharePoint, Javascript, PowerShell, and other technical stuff

Friday, October 9, 2015

SharePoint: How to delete Groups in every Site in a Site Collections

A feature (which I have accidentally activated some time ago) created in every Team Site a SharePoint Group called "Records Center Web Service Submitters for TeamsiteXYZ".

Now, instead removing the groups manually I want to do it with powershell.

Here the script:

$spWeb = Get-SPWeb "http://webapplication/sitecollection"
$spGroups = $spWeb.SiteGroups

Write-Host "This site has" $spGroups.Count "groups"

$groups = $spGroups | ? {$_.Name -like "Records Center Web Service Submitters for*"}
Write-Host "Found" $groups.Count "groups which will be deleted:"

ForEach($group in $groups) {
   Write-Host "Deleting" $group.Name "..."
   $spGroups.Remove($group.Name)
}

$spWeb.Dispose()

No comments:

Post a Comment