How to get a list of shared links in a SharePoint Online document library? Any PowerShell or other way?

Arun Kamle 0 Reputation points
2024-07-25T09:36:13.94+00:00

How to get a list of shared links in a SharePoint Online document library? Any PowerShell or other way (8016456551 ,??

Hi there How to get a list of shared links in a SharePoint Online document library? Any PowerShell or other way? (Shared links when we click on the ellipsis next to a folder/file, and click Share, and type th???

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,307 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Robin Sheng-MSFT 3,680 Reputation points Microsoft Vendor
    2024-07-26T02:39:48.1466667+00:00

    Hi @Arun Kamle

    Teams tag is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your question is not in our support scope.

    The following suggestion is for your reference:

     If you want to get a list of shared links in a SharePoint Online document library, you can use a PowerShell script to do so. Here is a sample script that helps you list shared links for all files in a document library:

    1. Install the SharePoint Online Administration Module:
         Install-Module -Name Microsoft.Online.SharePoint.PowerShell
      
    2. Connect to SharePoint Online:
         $adminUrl = "https://<your-tenant>-admin.sharepoint.com"
         Connect-SPOService -Url $adminUrl -Credential (Get-Credential)
      
    3. Get shared links in a document library:
         $siteUrl = "https://<your-tenant>.sharepoint.com/sites/<your-site>"
         $libraryName = "<your-library>"
         $items = Get-PnPListItem -List $libraryName -PageSize 1000
         
         foreach ($item in $items) {
             $sharingLinks = Get-PnPSharingLink -Identity $item.Id -List $libraryName
             foreach ($link in $sharingLinks) {
                 Write-Output "File: $($item.FieldValues.FileRef) - Link: $($link.Url)"
             }
         }
      

    Make sure to replace <your-tenant>, <your-site>, and <your-library> with your actual tenant, site, and document library names.


    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.



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.