当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 查找 SharePoint Online 文档库中的所有共享链接

作者:精品下载站 日期:2024-12-15 00:26:24 浏览:13 分类:玩电脑

查找 SharePoint Online 文档库中的所有共享链接


要求:我们希望找到通过 SharePoint Online 中的“共享”功能共享的所有链接。

PowerShell 在 SharePoint Online 中生成共享链接报告

在 SharePoint Online 中共享文件或文件夹时,它会生成一个链接,用户可以使用该链接根据在 SharePoint Online 中共享期间设置的权限进行查看或编辑。您有时可能想要审核所有共享链接。

[玩转系统] 查找 SharePoint Online 文档库中的所有共享链接

以下是用于为 SharePoint Online 文档库中的所有共享链接生成报告的 PowerShell 脚本:


#Parameters
$SiteUrl = "https://crescent.sharepoint.com/sites/Marketing"
$ReportOutput = "C:\Temp\SharedLinks.csv"
$ListName = "Branding"
   
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$Ctx = Get-PnPContext
$Results = @()
$global:counter = 0
 
#Get all list items in batches
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000
$ItemCount = $ListItems.Count
  
#Iterate through each list item
ForEach($Item in $ListItems)
{
    Write-Progress -PercentComplete ($global:Counter / ($ItemCount) * 100) -Activity "Getting Shared Links from '$($Item.FieldValues["FileRef"])'" -Status "Processing Items $global:Counter to $($ItemCount)";

    #Check if the Item has unique permissions
    $HasUniquePermissions = Get-PnPProperty -ClientObject $Item -Property "HasUniqueRoleAssignments"
    If($HasUniquePermissions)
    {        
        #Get Shared Links
        $SharingInfo = [Microsoft.SharePoint.Client.ObjectSharingInformation]::GetObjectSharingInformation($Ctx, $Item, $false, $false, $false, $true, $true, $true, $true)
        $ctx.Load($SharingInfo)
        $ctx.ExecuteQuery()
        
        ForEach($ShareLink in $SharingInfo.SharingLinks) 
        {
            If($ShareLink.Url)
            {            
                If($ShareLink.IsEditLink)
                {
                    $AccessType="Edit"
                }
                ElseIf($shareLink.IsReviewLink)
                {
                    $AccessType="Review"
                }
                Else
                {
                    $AccessType="ViewOnly"
                }
                
                #Collect the data
                $Results += New-Object PSObject -property $([ordered]@{ 
                Name  = $Item.FieldValues["FileLeafRef"]            
                RelativeURL = $Item.FieldValues["FileRef"]
                FileType = $Item.FieldValues["File_x0020_Type"]
                ShareLink  = $ShareLink.Url
                ShareLinkAccess  =  $AccessType
                ShareLinkType  = $ShareLink.LinkKind
                AllowsAnonymousAccess  = $ShareLink.AllowsAnonymousAccess
                IsActive  = $ShareLink.IsActive
                Expiration = $ShareLink.Expiration
                })
            }
        }
    }
    $global:counter++
}
$Results | Export-CSV $ReportOutput -NoTypeInformation
Write-host -f Green "Sharing Links Report Generated Successfully!"

此 PowerShell 生成包含详细信息的 CSV 报告:

  • 文件或文件夹的名称
  • 文件或文件夹的 URL
  • 文件类型
  • 分享链接
  • 访问类型 - 贡献或阅读
  • 是匿名访问
  • 有效期限等

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯