Problem Description:
if you need to remove all permissions and broken inheritances from a complete site collection, you may run this script
Resolution:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$site = Get-SPSite https://URL
$webs = $site.AllWebs
foreach ($web in $webs){
if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false ) ){
$web.ResetRoleInheritance()}
Write-Host “Removed broken inheritance on web: ” $web.Url -ForegroundColor Red
}
$lists=$web.Lists
foreach ($list in $lists){
if (($list -ne $null) -and ($list.HasUniqueRoleAssignments)){
$list.ResetRoleInheritance()
Write-Host “Removed broken inheritance on list: ” $list.Title -ForegroundColor Blue
Clear-Variable list
}
Write-Host “Entering list to remove single item permission: ” $list.Title
$items = $list.items | Where {$_.HasUniqueRoleAssignments}
foreach ($item in $items){
$item.ResetRoleInheritance()
Write-Host “Removed broken inheritance on item: ” $item.Name -ForegroundColor Green
Clear-Variable item
}}
$web.Dispose()
}
Remove all permissions
$groups = $web.SiteGroups
for ($i=0;$i -le $groups.Count;$i++){
$web.SiteGroups.Remove($groups[$i])
}
$users = Get-SPUser -Web $web -Limit all
for ($i=0;$i -le $users.Count;$i++){
Remove-SPUser -Web $web -Identity $users[$i] -Confirm:$false
}
(No Ratings Yet)
Loading...