I have a document library which has 3 folders in it and inside each folder there is a document (docx, xls, ppt).
My objective is to iterate every file inside my document library and check if It has unique permissions and If it does it should remove them.
For the folder part I already have this code working properly which fetches the root folder and prints if it has unique permissions.
$siteUrl = "https://**.sharepoint.com/sites/**"
Connect-PnPOnline –Url $siteURL –Credentials **
$context = Get-PnPContext
$ListName="List name"
$list = Get-PnPList $ListName
$folders = $list.RootFolder.Folders
$context.Load($folders);
$context.ExecuteQuery();
foreach($folder in $folders)
{
if($folder.ItemCount -gt 0)
{
$f = Get-PnPFolder -Url $folder.ServerRelativeUrl -Includes ListItemAllFields.RoleAssignments, ListItemAllFields.HasUniqueRoleAssignments
$context.Load($f);
$context.ExecuteQuery();
Write-Host $f.ServerRelativeUrl -> $f.ListItemAllFields.HasUniqueRoleAssignments
}
}
For the document / item part I'm struggling a bit because I cant seem to put this to work. It always gives me that the item is not part of a list.
So my questions is:
How do I check if a item / document has unique permissions and how to remove them?