sharepointsharepoint-2010sharepoint-2013

SharePoint - Grant permissions for multiple users


I have an Excel File that contain names of multiple users (99 users with their name and email), and i want to add all of them in one go in sharepoint, When i click in Members -> Add member : i can only put one user but i want to add multiple users, i want a way to automate the process ?


Solution

  • You can grant File Permissions from a CSV File using PowerShell:

    #Config Variables
    $SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
    $CSVFile = "C:\Temp\FolderPermissions.csv"
     
    Try {
        #Connect to PnP Online
        Connect-PnPOnline -Url $SiteURL -Interactive
     
        #Get the CSV file
        $CSVData = Import-CSV $CSVFile
      
        #Read CSV file and grant folder permissions
        ForEach($Row in $CSVData)
        {
            Try {
                #Get the Folder
                $Folder = Get-PnPFolder -Url $Row.FolderServerRelativeURL -Includes ListItemAllFields.ParentList -ErrorAction Stop
                $List =  $Folder.ListItemAllFields.ParentList
                #Get Users
                $Users =  $Row.Users -split ";"
                ForEach($User in $Users)
                {
                    #Grant Permission to the Folder
                    Set-PnPFolderPermission -List $List -Identity $Folder.ServerRelativeUrl -User $User.Trim() -AddRole $Row.Permission -ErrorAction Stop
                    Write-host -f Green "Ensured Permissions on Folder '$($Row.FolderServerRelativeURL)' to '$($User.Trim())'"
                }
            }
            Catch {
                Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
            }
        }
    }
    Catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
    

    For more detail information,please refer to: https://www.sharepointdiary.com/2021/01/sharepoint-online-grant-folder-permissions-from-csv-using-powershell.html#ixzz83SLtj4Ia