2

How to remove a single SPGroup from SiteGroups from my SiteCollection using PowerShell.When I tried my code I am getting collection was modified error. Lets say the group name is "Group1" and I want to extract this group name using the sitegroups method of site's rootweb and delete the same.

  • Are you trying to remove custom site groups? or the OOB ones – Asad Refai Apr 29 '15 at 9:40
  • @Asad, Thanks. Am trying to remove the one of the custom groups which is created by me.The name of the group is say "Group1". I have some 600+ SPGroups created and I want to delete this Group1 for a particular reason. – userAZLogicApps Apr 29 '15 at 9:45
5
$spWeb = Get-SPWeb "https://spdev"
$GroupName="Group 1"

if($spWeb.SiteGroups[$GroupName] -ne $null)
{
$spWeb.SiteGroups.Remove($GroupName)
$spWeb.Update()
Write-Host "Group Deleted!"
}
else
{
Write-Host "Group doesn’t Exists!"
}
0

You can do this using

$web = Get-SPWeb "http://siteurl"
$groups = $web.SiteGroups

$g = ("Group1")

ForEach($group in $g) {
   $groups.Remove($group)
}

$web.Dispose()
  • Never foreach while deleting or removing.. – George Norberg Sep 15 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.