You could try the below PowerShell script:
#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"
#Function to remove unique permissions and inherit from the parent
Function Remove-ListUniquePermissions
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $ListName
)
Try {
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#sharepoint online powershell inherit permissions
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$List.ResetRoleInheritance()
$List.Update()
$Ctx.ExecuteQuery()
Write-Host "Unique Permissions are removed and inherited from the Parent!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Unique Permissions!" $_.Exception.Message
}
}
#sharepoint online powershell reset permissions
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
#Call the function to remove unique permissions from a list
Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName
Note:
For more than 5000 items condition, you need to load the items with a row limit 5000 - if the result gives more than 5k then need to call the above function Remove-ListUniquePermission
Example of how to call the above function Remove-ListUniquePermission
$list = $ctx.Web.Lists.GetByTitle($DocLibName)
$ctx.Load($list)
$ctx.ExecuteQuery()
## View XML
$camlQuery= @"
<View Scope="RecursiveAll">
<Query>
<OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
</Query>
<RowLimit Paged="TRUE">5000</RowLimit>
</View>
"@
$currentCollection = $list.GetItems($camlQuery)
$ctx.Load($currentCollection)
$ctx.ExecuteQuery()
if ($currentCollection -eq 5000)
{
Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName
}
Source:
Delete Unique Permissions on a List or Library in SharePoint Online using PowerShell:
Get All Items in 5000+ large list with CSOM in PowerShell