What PowerShell command/script can give a user direct permission to a file in /SPonlineSite/shared documents/folder/file.doc?

frob 4,261 Reputation points
2021-08-20T17:50:10.517+00:00

Hi there

What PowerShell command/script can give a user direct permission to a file in /SPonlineSite/shared documents/folder/file.doc?
(Direct permissions to the file, without adding the user to any SP Group)

Thank you.

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

Accepted answer
  1. Echo Du_MSFT 17,316 Reputation points
    2021-08-23T02:35:02.37+00:00

    Hi @frob ,

    Please following steps:

    1.Add "ID" column to Document Library View

    125357-3.png

    2.Please run the following powershell script as an admin to grant user permissions

    #Config Variables  
    $SiteURL = "https://tenant.sharepoint.com/sites/Du"  
    $LibraryName ="Documents"  
    $ItemID ="12"  
    $UserID="******@tenant.onmicrosoft.com"  
    
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    
    #Grant permission to User  
    Set-PnPListItemPermission -List $LibraryName -Identity $ItemID -AddRole "Read" -User $UserID  
    

    125434-4.png

    Thanks,
    Echo Du

    ====================================

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.