Búsqueda de sitios web

Generar informe de permisos de enlaces compartidos en SharePoint Online


Requisito: Genere un informe de permisos para todos los enlaces compartidos a través de la función "Compartir" de SharePoint Online.

Obtenga todos los permisos de enlaces compartidos en la biblioteca de documentos de SharePoint Online mediante PowerShell

Cuando comparte un archivo o carpeta en SharePoint Online, se rompe la herencia de permisos del elemento en particular y otorga permisos únicos.

Aquí está el script de PowerShell para escanear todos los enlaces compartidos en una biblioteca de documentos y exportarlos a un informe CSV.


# 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!"

Este script genera todos los vínculos compartidos a un informe CSV desde una biblioteca de documentos de SharePoint Online. Para eliminar enlaces compartidos en SharePoint Online con PowerShell, consulte ¿Cómo eliminar todos los enlaces compartidos en SharePoint Online usando PowerShell?

Artículos relacionados