Assign permissions for multiple files (without using a folder)

Jindriska 21 Reputation points
2023-10-14T17:37:49.25+00:00

Hello
How can I assign permissions (f.e. read for a certain Sharepoint Group) to multiple files within a library?

(without adding a folder) When I select multiple files I can change the properties, the columt values, for multiple files at ones but not the permissions.

Best regards

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
{count} votes

Accepted answer
  1. Yanli Jiang - MSFT 24,356 Reputation points Microsoft Vendor
    2023-10-17T02:46:57.8466667+00:00

    Hi @Adriana Mikolaskova Nautsch (MNG) ,

    OK, I understand. But unfortunately, Power Automate is currently not supported in the Q&A forum. I'm not very familiar with it either.

    I just found some articles for your reference:

    https://powerusers.microsoft.com/t5/Building-Flows/Add-user-group-permissions-to-a-file-in-a-sharepoint-library/td-p/1338558

    https://learn.microsoft.com/en-us/sharepoint/dev/business-apps/power-automate/guidance/manage-list-item-file-permissions

    If you still have questions or would like more details, please start a new discussion via the Power Automate Community so that you can get dedicated support on this issue.

    Thanks for your understanding. :-)


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Yanli Jiang - MSFT 24,356 Reputation points Microsoft Vendor
    2023-10-16T06:17:04.3566667+00:00

    Hi @Jindriska ,

    To grant permissions to files in batches, you can use a PowerShell script to make it.

    The following script example gives permissions to all files in a library:

    #Set Variables
    $SiteURL = "https://tenant.sharepoint.com/sites/sitename"
    $ListName="Documents"
    $ParentFolderURL = "/Shared Documents" #Site Relative Path of the document Library
    $GroupName
    $Role = "Edit"
      
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
     
    #Get all Files from the Folder
    $AllFiles = Get-PnPFolderItem -ItemType File -FolderSiteRelativeUrl $ParentFolderURL
     
    #Iterate through each File in the Folder
    ForEach($File in $AllFiles)
    {
        #Grant permissions to the File
        Set-PnPListItemPermission -List $ListName -Identity $File.ListItemAllFields -User $UserAccount -AddRole $Role
        Write-host ("Granted Permission to '{0}' at {1} " -f $File.Name,$File.ServerRelativeUrl)
    }
    
    
    #Read more: https://www.sharepointdiary.com/2019/01/sharepoint-online-grant-permission-to-all-files-in-a-folder-using-powershell.html#ixzz8GHOruoFl
    

    If the files you need to operate are only part of the library, there are to choices you can try:

    1, You can choose to put their names into the csv file and then grant permissions. The changes to the script are as follows:

    Add statement:

    #SetVariables
    $file = "C:\Users\spadmin\Desktop\csvfile.csv"
    #Get the CSV file
    $csv = Import-CSV $file
    

    Remove statement:

    $AllFiles = Get-PnPFolderItem -ItemType File -FolderSiteRelativeUrl $ParentFolderURL
    
    

    2, You can put these files into one folder, so that you only need to change the $ParentFolderURL parameter in this script can be done.

    For more details, please refer to:

    https://www.sharepointdiary.com/2019/01/sharepoint-online-grant-permission-to-all-files-in-a-folder-using-powershell.html


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Jindriska 21 Reputation points
    2023-10-16T15:12:47.67+00:00

    Thank you.
    Unfortunately I don't think I will get Access to the Powershell.
    Is there a way to do this with PowerAutomate?

    0 comments No comments