Is there any PowerShell or other script way to grant a user “Restricted View” permission on folders and files in a SharePoint Online document library?

frob 4,261 Reputation points
2022-08-04T20:48:37.53+00:00

Hi there
Is there any PowerShell or other script way to grant a user “Restricted View” permission on folders and files in a SharePoint Online document library?
Thanks.

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2022-08-05T10:13:26.757+00:00

    Hi @frob , After my testing and research, you can manually grant a user "Restricted View" permission in the sharepoint interface. 228514-image.png But 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). 228515-image.png But you can do that by adding the " Restricted View " permission level (location in the picture above) and then using powershell. There are steps:

    1. 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.) 228541-image.png 2.Use the following PnP powershell code: $SiteURL = "https://xxxxxxxx" $DocumentName ="xxxx" $UserID="xxx@X .com" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Break Permission Inheritance of the List Set-PnPList -Identity $DocumentName -BreakRoleInheritance -CopyRoleAssignments #Grant permission on List to User Set-PnPListPermission -Identity $DocumentName -AddRole " Restricted View " -User $UserID

    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 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.