question

frob avatar image
0 Votes"
frob asked HRisbud-4433 answered

On a SharePoint Online site - what PowerShell code can read a CSV file > break inheritance on the document library folders > grant permissions to external users like this?

Hi there

On a SharePoint Online site - what PowerShell code can read the following CSV file > break inheritance on the document library folders > grant direct permissions to external users (not adding them to a group).

CSV file:

Site, DocLibPath, ExternalUserLogin, DesiredPermissions
http://domain.sharepoint.com/sites/site1, /DocLib1/ChildFolder1, john@hotmail.com, Read Only
http://domain.sharepoint.com/sites/site1, /DocLib1/ChildFolder1, peter@gmail.com, Contribute
http://domain.sharepoint.com/sites/site2, /DocLib1/ChildFolder2/ChildFolder3, jessica@gmail.com, Contribute
http://domain.sharepoint.com/sites/site3, /DocLib2/ChildFolder2, mary@somevendor.com, Read Only
http://domain.sharepoint.com/sites/site1, /DocLib3/ChildFolder3, mary@somevendor.com, Read Only

Thank you so much.

office-sharepoint-onlinewindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HRisbud-4433 avatar image
0 Votes"
HRisbud-4433 answered

Try this for internal users - not sure about external users...

NOTE: this is not tested code... try it on your own

 $ImportFile = "<file location>"
 $P = Import-Csv -Path $ImportFile
 $P | ForEach-Object {
     #Site, DocLibPath, InternalUserLogin, DesiredPermissions
     $sID = $_.'Site'
     $DocLibPath = $_.'DocLibPath'
     $InternalUserLogin = $_.'InternalUserLogin'
     $DesiredPermissions = $_.'DesiredPermissions'
    
     #connect to site
     $destConn = Connect-PnPOnline -Url $sID -UseWebLogin -ReturnConnection
        
     $TargetLibrary = Get-PnPList -Identity $DocLibPath -Connection $destConn
    
     #$TargetLibrary - /sites/site1/DocLib1
     #$DocLibPath - /sites/site1/DocLib1/ChildFolder1
     #$InternalUserLogin - john.doe@abcdcorp.com
     #$DesiredPermissions - Read
     Set-PnPFolderPermission -List $TargetLibrary -Identity $DocLibPath -User $InternalUserLogin -AddRole $DesiredPermissions
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ElsieLu-MSFT avatar image
0 Votes"
ElsieLu-MSFT answered ElsieLu-MSFT commented

Hi @frob ,

According to my research, due to SPO's security restrictions, I'm afraid that there is currently no such powershell that can grant different permissions to external users from csv.

Reference:
SharePoint Online: How to Add External User using PowerShell?
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 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.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Elsie
Ok, if we forget the CSV file - How about PowerShell to grant permission to a single external user directly, (without using a group)?

Thank you.

0 Votes 0 ·

Hi @frob ,

We are currently looking into this needs and will give you an update as soon as possible. Thank you for your understanding and support.

Thanks,
Elsie Lu

0 Votes 0 ·

Hi @frob,

I noticed that you have posted a post for the convenience of users in need:

On a SharePoint Online Library > Folder - What PowerShell command/code can grant permissions to an external user (directly, without adding him to a group)?

Thank you again for your contribution. :)

0 Votes 0 ·