Encuentre todos los enlaces compartidos en la biblioteca de documentos de SharePoint Online
Requisito: Queríamos encontrar todos los enlaces compartidos a través de la función "Compartir" en SharePoint Online.
PowerShell para generar informes de enlaces compartidos en SharePoint Online
Cuando un archivo o carpeta se comparte en SharePoint Online, genera un vínculo y los usuarios pueden usarlo para verlo o editarlo según los permisos establecidos durante Compartir en SharePoint Online. Es posible que desees auditar todos los enlaces compartidos en ocasiones.
Aquí está el script de PowerShell para generar un informe para todos los enlaces compartidos en una biblioteca de documentos de SharePoint Online:
#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!"
Este PowerShell genera un informe CSV con detalles:
- Nombre del archivo o carpeta
- URL del archivo o carpeta
- Tipo de archivo
- Compartir enlace
- Tipo de acceso: Contribuir o Leer
- Es acceso anónimo
- Fecha de vencimiento, etc.
