Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to delete unique permissions from a subsite and delete subsite... But while breaking the  inheritance the permissions are getting changed and thepermissions are intact at the root level

How can i delete the permission retreving the permissions with subsite title from the root site and delete them?


$web = Get-SPWeb $ssite 
    if($web){
     #Reset broken inheritance
      $web.ResetRoleInheritance()
        # Check if web has Unique permission - Root webs always uses Unique permission 
        if (($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false)){ 
              <#foreach($roleAssignment in $web.RoleAssignments){ 
                         $group = $web.SiteGroups[$roleAssignment.Member.Name];
                         $web.SiteGroups.Remove($group)
                         $web.Update();
                         Write-Host "Group Deleted-" $group -ForegroundColor Green 
             }#foreach    #>
             for($i=$web.RoleAssignments.Count-1;$i -ge 0; $i--){ 
                                Write-Host($web.RoleAssignments[$i].Member.Name);
                                $group = $web.SiteGroups[$web.RoleAssignments[$i].Member.Name];
                               	$web.RoleAssignments.Remove($group);
								$web.Update();
                                Write-Host "Group Deleted-" $group -ForegroundColor Green 
                    }   

        }#if
        else{Write-host "Site doesn't have any unique permissions " $web.URL -ForegroundColor Red }
        $web.Dispose()
    }#if


What I have tried:

delete unique permissions from a subsite and delete subsite


$web = Get-SPWeb $ssite 
    if($web){
     #Reset broken inheritance
      $web.ResetRoleInheritance()
        # Check if web has Unique permission - Root webs always uses Unique permission 
        if (($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false)){ 
              <#foreach($roleAssignment in $web.RoleAssignments){ 
                         $group = $web.SiteGroups[$roleAssignment.Member.Name];
                         $web.SiteGroups.Remove($group)
                         $web.Update();
                         Write-Host "Group Deleted-" $group -ForegroundColor Green 
             }#foreach    #>
             for($i=$web.RoleAssignments.Count-1;$i -ge 0; $i--){ 
                                Write-Host($web.RoleAssignments[$i].Member.Name);
                                $group = $web.SiteGroups[$web.RoleAssignments[$i].Member.Name];
                               	$web.RoleAssignments.Remove($group);
								$web.Update();
                                Write-Host "Group Deleted-" $group -ForegroundColor Green 
                    }   
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900