Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

Get list of all documents with unique permissions (Power Automate)

Posted on April 12, 2023April 12, 2023 by Tom

“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.

Power Automate documents unique permissions

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.

Power Automate documents unique permissions

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.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

1 thought on “Get list of all documents with unique permissions (Power Automate)”

  1. Priya Sivaji says:
    May 23, 2023 at 2:26 pm

    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

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes