Sometime we need to reset the unique permission for document library, sub folders and files. If the document library has only 1-2 documents then we can handle it manually, but if you have thousands of files and folder so its quite difficult to reset it for all one by one. Below piece of code can help to reset unique permission for document library and its content. This script will take the top level permission from document library.
function ResetUniquePermission { Param( [Parameter(Mandatory = $true, HelpMessage="Enter the site url")][ValidateNotNullorEmpty()][string] $SiteURL , [Parameter(Mandatory = $true, HelpMessage="Enter the library name")][ValidateNotNullorEmpty()][string] $LibraryName, [Parameter(Mandatory = $true, HelpMessage="Total number of files")][ValidateNotNullorEmpty()][int] $TotalFiles ) $Web = Get-SPWeb $SiteURL $List= $Web.Lists[$LibraryName] $Query = New-Object Microsoft.SharePoint.SPQuery $Query.ViewXml = @" <View Scope="RecursiveAll"> <Query> <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy> </Query> <RowLimit Paged="TRUE">$TotalFiles</RowLimit> </View> "@; $Items = $List.GetItems($Query) for($j=0;$j -lt $Items.Count ;$j++) { $Items[$j].ResetRoleInheritance() Write-Host "Permission reset done for file "$Items[$j]["Title"] -ForegroundColor Green } }