“I’d like to restore original permissions on all documents in a SharePoint library, how can I list files with unique permissions in a Power Automate flow?”
When restoring library permissions, it’ll remove all unique permissions on the library itself and use the site permissions instead. But that doesn’t mean it’ll restore permissions also on all the files in that library. If the permission inheritance is broken, the library settings doesn’t have any effect on such files.
Yet often you want to restore all permissions, on all the folders and all the files. How do you do that? How do you list all the files/folders with unique permissions to inherit them again?
Get the files with an HTTP request
The good news is that each file in the document library has a property called ‘HasUniqueRoleAssignments’ that’ll give you such information. The bad news is that this property is not accessible using the ‘Get files (properties only)’ action. As such, you’ll need an HTTP request to SharePoint where you’ll ask for this property specifically with the $select parameter. Since you’ll need also the id of the item to restore the permissions, take also the id.
Method: GET
Uri: _api/web/lists/getByTitle('<libraryName>')/items?$select=HasUniqueRoleAssignments,id
Notes: <…> are placeholders, replace them including the < and >. If you’d like also the file name/path/type you can add the corresponding properties to the $select.
This action will return all files in the library, not only the ones with unique permissions…
You’ll have to filter the results using the ‘Filter array’ action to keep only files whose ‘HasUniqueRoleAssignments’ equals true.
Navigate in the HTTP request output to get the array with the results…
body('Send_an_HTTP_request_to_SharePoint')?['d']?['results']
…and keep only the files whose HasUniqueRoleAssignments is true.
item()?['HasUniqueRoleAssignments']
The result will be only files with unique permissions. As you have their id, you can restore them to the original permissions – file by file, folder by folder.
Summary
To restore permissions on all files and folders in a SharePoint library, you must know ids of these files. And even though Power Automate doesn’t have a dedicated action that would list those documents with unique permissions, there’s still an HTTP request to save the day. List all the files including the ‘HasUniqueRoleAssignments’ property, filter only the ones where it’s true, and restore the permissions with another HTTP request.
This is great!!! I am just stuck in the last part- Apply to each – Send an HTTP request to SharePoint 2 – the item() expansion could you please provide a screen capture of how you added the ID of the HasUniqueRoleAssignment items
Hello Priya,
it’s in the note of the action – expression item()?[‘id’]
I’m trying to use this with our Sharepoint site, but I’m getting the error, “A potentially dangerous Request.Path value was detected from the client.”
I’m guessing that the issue is that Documents has 126,000 files. I’m not sure how to get around this.
Hello Jim,
me neither, I’ve never seen this error.
I have the same problem as Priya. How do you get the id from the filtered array?
Never mind. I found it. The expression: item()[‘ID’]
Hello, this has been helpful but I’m also wondering how would I be able to retrieve what permission level was given to that certain item?
Hello Dev,
I guess it’s possible, I’ll add it to my list of potential future topics
Hi Tom,
What if I only want to get a list of the files with unique permissions and email the owner?
Hello Steve,
the ‘Filter array’ will give you Id’s of the files – you can take it, get the properties for each of the files including e.g. the author (owner?), and send him an email.