如何使用Powershell共享OneDrive文件?

时间:2020-04-15 13:00:52

标签: powershell sharepoint file-permissions onedrive

我在OneDrive的子焊料中有3个文件,说“ Documens / TopFolder / SubFolder”

我可以使用以下子文件夹列出3个文件

Get-PnPFolder -FolderRelativeUrl "Documens/TopFolder/SubFolder"
File1.xlsx
File2.xlsx
File3.xlsx

现在我想与3个不同的用户共享这3个文件

  • 具有User1@abc.com的File1
  • 具有User2@abc.com的File2
  • 具有User3@abc.com的File3

我是组织中的用户,因此我没有管理员权限来访问共享点。我刚刚开始学习Powershell。

问题是:

  1. 如何将这3个文件放入Get-PnPListItem中?

  2. 如何使用Windows Powershell授予每个文件的权限?

  3. 如何获取每个文件的匿名网址链接,以与单个用户共享?

2 个答案:

答案 0 :(得分:0)

您可以使用Set-PnPListItemPermission授予用户权限。示例:

Set-PnPListItemPermission -List 'Documents' -Identity 1 -User 'user@contoso.com' -AddRole 'Contribute'

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitempermission?view=sharepoint-ps

以下文章可能对您有所帮助:

https://www.sharepointdiary.com/2016/09/sharepoint-online-set-folder-permissions-powershell.html

https://www.sharepointdiary.com/2017/11/sharepoint-online-grant-permission-to-list-item-using-powershell.html

答案 1 :(得分:0)

我找到了一种基于FileName填充ListItem并获取标识号的方法。 如下

#Set Variables
$SiteURL= "https://abc-my.sharepoint.com/personal/Testing/"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin

$ListName="Documents"
#Get All Files from the document library - In batches of 500 and filter File Names Starting with "File_"
$ListItems = Get-PnPListItem -List $ListName -PageSize 500 | Where {$_["FileLeafRef"] -like "File_*"} 
ForEach($Item in $ListItems)
{


    $DocumentsData += New-Object PSObject -Property @{
    FileName = $Item.FieldValues['FileLeafRef']
    FileURL = $Item.FieldValues['FileRef']
    FileID = $Item.FieldValues['ID']
    }

}

$DocumentsData 

Set-PnPListItemPermission -List 'Documents' -Identity 1 -User 'Test1@abc.com' -AddRole 'Contribute'

Send-PnPMail -To Test1@abc.com -Cc Test2@abc.com  -Subject "Your OD File Link" -Body "Here is the WEB URL LINK"

是否有任何PnpAPI可以获取OneDrive上文件的匿名URL链接,我可以将其放在电子邮件的-Body字符串中?