1.You could reset unique permissions for all files in a folder by using below PnP PowerShell.
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$FolderServerRelativeURL = "/sites/Marketing/Branding/2018"
#Connect to the site
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Folder from given URL
$Folder = Get-PnPFolder -Url $FolderServerRelativeURL -Includes ListItemAllFields.ParentList
$ParentList = $Folder.ListItemAllFields.ParentList.Title
#Get All Files from the Folder
$Files = Get-PnPListItem -List $ParentList -FolderServerRelativeUrl $Folder.ServerRelativeUrl | Where {$_.FileSystemObjectType -eq "File"}
#Traverse through each file in the folder
ForEach ($File in $Files)
{
#Check If File has Unique Permissions
$HasUniquePermissions = Get-PnPProperty -ClientObject $File -Property HasUniqueRoleAssignments
If($HasUniquePermissions)
{
#Reset Broken Inheritance
$File.ResetRoleInheritance()
$File.update()
Invoke-PnPQuery
Write-Host "Reset Unique Permissions on File $($File.FieldValues["FileRef"])" -ForegroundColor Green
}
}
2.You could run below PowerShell to remove unique permissions on one folder.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables
$SiteURL = "https://tenant.sharepoint.com/sites/emilytest"
$FolderServerRelativeUrl= "/Sites/emilytest/Shared Documents/2022"
Try {
#Get Credentials to connect
$Cred= Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the web from URL
$Web = $Ctx.web
$Ctx.Load($Web)
$Ctx.executeQuery()
#Get the Folder object by Server Relative URL
$Folder = $Web.GetFolderByServerRelativeUrl($FolderServerRelativeUrl)
$Ctx.Load($Folder)
$Ctx.ExecuteQuery()
#Reset Folder Permissions
$Folder.ListItemAllFields.ResetRoleInheritance()
$Ctx.ExecuteQuery()
Write-host -f Green "Folder's Unique Permissions are Removed!"
}
Catch {
write-host -f Red "Error Resetting Folder Permissions!" $_.Exception.Message
}