I have a need to remove unique permissions on documents in a list, however, the list is over 5000 items so the following won't work, and its SharePoint Online so I can't change the threshold.
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext("https://www.example.com/subSite/")
$password = ConvertTo-SecureString -string "MyPassword" -AsPlainText -Force
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("admin@mytenant", $password)
$ll=$ctx.Web.Lists.GetByTitle("Company Docs")
$ctx.Load($ll)
$ctx.ExecuteQuery()
$spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$spQuery.ViewXml ="<View Scope='Recursive' />";
$itemki=$ll.GetItems($spQuery)
$ctx.Load($itemki)
$ctx.ExecuteQuery()
for($j=0;$j -lt $itemki.Count ;$j++)
{
$itemki[$j].ResetRoleInheritance()
$ctx.ExecuteQuery()
}
As an alternative, if I can specify a sub-folder I have a chance of getting this working.
Something like:
$spQuery.FolderServerRelativeUrl= "/SubSite/Company Docs/Folder1/"
I can't seem to get this to work though, any thoughts?