Hi @vincent manzari ,
You cannot use PnP PowerShell to directly grant users "Restricted View" permissions to folders and files in a SharePoint Online document library. Because the "Restricted View" permission is a hidden permission level as shown below(Not displayed by default in the Permission level).
But you can do that by adding the " Restricted View " permission level and then using powershell. There are steps:
- Library setting-> permission for this document library -> Add " Restricted View " permission level.(You need to Select the permissions to include in this permission level yourself.)
- Use the following PnP powershell code:
#Config Variables
$SiteURL = "https://domain.sharepoint.com/sites/xxx"
$ListName="Documents"
$FolderServerRelativeURL = "/sites/xxx/Shared Documents/xxx"
$UserAccount = "******@domain.com"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the Folder from URL
$Folder = Get-PnPFolder -Url $FolderServerRelativeURL
#Grant Permission to a Folder
Set-PnPListItemPermission -List $ListName -Identity $Folder.ListItemAllFields -User $UserAccount -AddRole 'Restricted View'
For more information, please refer to:
https://www.sharepointdiary.com/2016/09/sharepoint-online-set-folder-permissions-powershell.html
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
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.