How to get Shared link URL of the file which present in manage access of the SharePoint

Surjit Kumar A 20 Reputation points
2024-05-10T14:12:52.3933333+00:00

User's image

how to get the the link URL which present in the manage access of the file in the SharePoint mentioned in the image using PowerShell

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,931 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 19,090 Reputation points Microsoft Vendor
    2024-05-13T02:19:06.7333333+00:00

    Hi @Surjit Kumar A,

    Thank you for posting in this community.

    Please try this PnP PowerShell:

    #Parameters
    $SiteUrl = "https://contoso.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!"
    
    

    Here is my result:

    enter image description here


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Matthias 20 Reputation points
    2024-12-03T14:10:46.4633333+00:00

    Is there a way to remove Shared link with Powershell?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.