【问题标题】:How to share a OneDrive file using powershell?如何使用 powershell 共享 OneDrive 文件?
【发布时间】:2020-07-28 11:06:03
【问题描述】:

我的 OneDrive 子焊盘中有 3 个文件,例如“Documens/TopFolder/SubFolder”

我可以在这个子文件夹中列出 3 个文件使用

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

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

  • 文件 1 与 User1@abc.com
  • 文件 2 与 User2@abc.com
  • 文件 3 与 User3@abc.com

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

问题是:

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

  2. 如何使用 windows powershell 为每个文件授予权限?

  3. 如何获取每个文件的匿名 weburl 链接以与个人用户共享?

【问题讨论】:

    标签: powershell sharepoint file-permissions onedrive


    【解决方案1】:

    您可以使用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

    【讨论】:

    • 感谢 Michael Han 调查。但是,如何知道每个文件的 -Identity # ?
    【解决方案2】:

    我找到了一种方法来填充基于 FileNames 的 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 字符串中?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2022-06-22
      相关资源
      最近更新 更多