2

I want to remove all unique permissions on one site from all locations on it, whether they are lists, libraries, list items, folders or docs in libraries. All unique permissions must be removed.

I found PS script to delete unique permissions on lists or on site, but that's it, no examples to remove from all locations.

scripts I found are bellow:
for site:

$WebURL ="#"
$web = Get-SPWeb $WebURL
if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false ) )
{
  $web.ResetRoleInheritance()
  Write-host "Broken Inheritance Reset on web:" $web.URL
}

for list:

$WebURL ="#"
$Web = Get-SPWeb $WebURL
$ListColl =  $web.lists | Where-Object
{
  ($_.HasUniqueRoleAssignments -eq $true)  -and ($_.hidden -eq $false)
}
foreach($list in $ListColl) #if($list) #Exists
{
  $list.ResetRoleInheritance()
  Write-host "Broken Inheritance Reset on List:" $list.Title
}

Any help?

3
  • All you have to do is break inheritance from all lists(document libraries and plain lists) and subsites and item level permssions in individual list. Thats it.
    – Shiva
    Commented Jun 21, 2016 at 8:29
  • and that is why I asked for help with powershell script
    – Danilo
    Commented Jun 21, 2016 at 8:35
  • Is the above script not working.
    – Shiva
    Commented Jun 21, 2016 at 8:38

3 Answers 3

4

Try this

#Variable for Web URL
$WebURL ="Your URL "

# Varibale to hold document count 
$count = 0

#get Web object
$Web = Get-SPWeb $WebURL

if ( ($web.HasUniqueRoleAssignments) -and ($web.IsRootWeb -eq $false ) )
{
  $web.ResetRoleInheritance()
  Write-host "Broken Inheritance Reset on web:" $web.URL
}

#Get Lists with Unique permissions - Exclude Hidden lists
$ListColl =  $web.lists | Where-Object  {  ($_.HasUniqueRoleAssignments -eq $true)  -and ($_.hidden -eq $false) }

#Enumerate through each list and reset permission inheritance
foreach($list in $ListColl) #if($list) #Exists
 {
      #Reset list inheritance
      $list.ResetRoleInheritance()
      Write-host "Broken Inheritance Reset on List:" $list.Title

        foreach ($folder in $list.Folders)
         { 
            if ($folder.HasUniqueRoleAssignments)
            {
              Write-Host "Resetting Folder inheritance at:" $folder.Url  
              $folder.ResetRoleInheritance() 
              $folder.Update()
            }
         }  


#Get all items with unique permissions 
    $itemsWithUniquePermissions = $list.GetItemsWithUniquePermissions() 
    Write-Host $itemsWithUniquePermissions.Count "number of items with unique permissions found." 

    # Only update items if some exist 
    if ($itemsWithUniquePermissions.Count -gt 0) { 
        foreach ($itemInfo in $itemsWithUniquePermissions) { 
            $item = $list.GetItemById($itemInfo.Id) 
                $item.ResetRoleInheritance() 
            $count++ 
        } 

        # Display number of items updated 
        Write-Host "Updated permissions on $count items." -foregroundcolor Green 
    }
 $web.Dispose() 

 }

//We can also delete unique permissions of all list items in a single line as:

(Get-SPweb $WebURL).Lists["$list.Title"].Items | Foreach-Object{ $_.ResetRoleInheritance() }

Hope this wil help you

3
  • it's not doing whole job. it leaves unique permissions on docs and folders in libraries.
    – Danilo
    Commented Jun 21, 2016 at 9:19
  • Are you getting any error message? Before foreach loop check whether folders and item available. condition to check $folders = $list.Folders if ($folders.Count -gt 0) and $list_items = $list.Items if ($list_items.Count -gt 0)
    – Sabitha S
    Commented Jun 21, 2016 at 10:27
  • i found problem at the code you provided. I need to put folders inside { } of the upper check for lists/libraries. here, foreach($list in $ListColl). I managed to remove all unique permissions except for documents whose perent folders don't have unique permissions :)
    – Danilo
    Commented Jun 21, 2016 at 11:24
1

So, I managed to find a solution for my question.
Bellow is Powershell script code:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Variable for Web URL
$WebURL ="#"

#get Web object
$Web = Get-SPWeb $WebURL

#Get Lists with Unique permissions - Exclude Hidden lists
$ListColl =  $web.lists | Where-Object  { ($_.hidden -eq $false) }
#Enumerate through each list and reset permission inheritance  
foreach($list in $ListColl)
{
 #Reset list inheritance
 $list.ResetRoleInheritance()
 Write-host "Broken Inheritance Reset on List:" $list.Title

 $items = $list.Items | Where-Object{$_.HasUniqueRoleAssignments};
 foreach($item in $items)
 {
  #Reset broken list item inheritance
  $item.ResetRoleInheritance()
  Write-host "Broken Inheritance Reset on List Item:" $item.URL
 }
 #}
$folders = $list.Folders
if ($folders.Count -gt 0)
{
 foreach ($folder in $folders) 
 {
  if ($folder.HasUniqueRoleAssignments -eq $True)
  {
    $folder.ResetRoleInheritance()
    $folder.update()
  }
 }
}
}

And that's it, this script removes all unique permissions on all docs, items, lists, libraries, folders on one site.
I used this page for start point:
http://www.sharepointdiary.com/2014/12/delete-unique-permissions-reset-broken-inheritance-using-powershell.html

0

For folders try the following:

$folders = $list.Folders
if ($folders.Count -gt 0)
{
    foreach ($folder in $folders) 
    {
        if ($folder.HasUniqueRoleAssignments -eq $True)
        {
            $folder.ResetRoleInheritance()
            $folder.update()
        }
    }
}

For list items, try the following:

$list_items = $list.Items
if ($list_items.Count -gt 0)
{
    foreach ($list_item in $list_items) 
    {
        if ($list_item.HasUniqueRoleAssignments -eq $True)
        {
            $list_item.ResetRoleInheritance()
            $list_item.update()
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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