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

[玩转系统] 在 SharePoint Online 中生成共享链接权限报告

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

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


要求:为通过 SharePoint Online 的“共享”功能共享的所有链接生成权限报告。

使用 PowerShell 获取 SharePoint Online 文档库中的所有共享链接权限

当您在 SharePoint Online 中共享文件或文件夹时,它会破坏特定项目的权限继承并授予唯一的权限。

[玩转系统] 在 SharePoint Online 中生成共享链接权限报告

以下是用于扫描文档库中所有共享链接并将其导出到 CSV 报告的 PowerShell 脚本。


# Parameters
$SiteUrl = "https://Crescent.sharepoint.com/sites/Marketing"
$ReportOutput = "C:\Temp\SharingLinkPermissions.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 Users and Assigned permissions
        $RoleAssignments = Get-PnPProperty -ClientObject $Item -Property RoleAssignments
        ForEach($RoleAssignment in $RoleAssignments)
        {
            $Members = Get-PnPProperty -ClientObject $RoleAssignment -Property RoleDefinitionBindings, Member
            #Get list of users 
            $Users = Get-PnPProperty -ClientObject ($RoleAssignment.Member) -Property Users -ErrorAction SilentlyContinue
            #Get Access type
            $AccessType = $RoleAssignment.RoleDefinitionBindings.Name
            If ($RoleAssignment.Member.Title -like "SharingLinks*")
            {
                If ($Users -ne $null) 
                {
                    ForEach ($User in $Users)
                    {
                        #Collect the data
                        $Results += New-Object PSObject -property $([ordered]@{ 
                        Name  = $Item.FieldValues["FileLeafRef"]            
                        RelativeURL = $Item.FieldValues["FileRef"]
                        FileType = $Item.FieldValues["File_x0020_Type"]
                        UserName = $user.Title
                        UserAccount  = $User.LoginName
                        Email  =  $User.Email
                        Access = $AccessType
                        })
                    }
                       
                }
            }        
        }
    }       
    $global:counter++
}
$Results | Export-CSV $ReportOutput -NoTypeInformation
Write-host -f Green "Sharing Links Report Generated Successfully!"

此脚本从 SharePoint Online 文档库生成 CSV 报告的所有共享链接。若要使用 PowerShell 删除 SharePoint Online 中的共享链接,请参阅如何使用 PowerShell 删除 SharePoint Online 中的所有共享链接?

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

取消回复欢迎 发表评论:

关灯