Thursday 7 January 2016

Delete all SharePoint Groups for list level using PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$web = Get-SPWeb http://site-name/Inst/site
$list = $web.Lists.TryGetList("Deleted Documents")
if($list.HasUniqueRoleAssignments -eq $False)
{
$list.BreakRoleInheritance($True)
}
[Microsoft.SharePoint.SPRoleAssignmentCollection] $spRoleAssignments=$list.RoleAssignments

for([int] $a=$spRoleAssignments.Count-1; $a -ge 0;$a--)
{
$spRoleAssignments.Remove($a);
}
$web.Dispose()