Shared with External users report - how to get the actual links

sal 0 Reputation points
2025-05-06T17:02:21.8133333+00:00

Shared with External users report - how to get the actual links

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,941 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Finn Dang 0 Reputation points
    2025-05-11T03:51:28.9466667+00:00

    Dear Sal,

    I hope you’re doing well.

    To include the actual URLs in your “Shared with External Users” report, you can try one of these approaches:

    1. Use the SharePoint admin center export
      • In the SharePoint admin center, go to Reports → Sharing → Shared with external users.
      • Click Export—the downloaded CSV should include a Direct Link column with the full URL for each item.
    2. Enhance the CSV via PnP PowerShell
      1. Install and connect PnP PowerShell: Install-Module PnP.PowerShell Connect-PnPOnline -Url https://<your-tenant>-admin.sharepoint.com -Interactive
      2. Import your exported report and append the web URLs:
              $report = Import-Csv -Path "C:\Reports\SharedWithExternalUsers.csv"
              $enhanced = foreach ($row in $report) {
                # Connect to the site where the file lives
                Connect-PnPOnline -Url $row.SiteUrl -Interactive
                # Retrieve the file to get its FileRef (web URL)
                $fileItem = Get-PnPFile -Url $row.'Site Relative URL' -AsListItem
                [PSCustomObject]@{
                  SiteUrl   = $row.SiteUrl
                  FileName  = $row.'File Name'
                  DirectLink= "https://<your-tenant>.sharepoint.com" + $fileItem.FieldValues.FileRef
                }
              }
              $enhanced | Export-Csv -Path "C:\Reports\SharedWithExternalUsersWithLinks.csv" -NoTypeInformation
        
      3. The new CSV will have a DirectLink column containing each item’s actual URL.
    3. Query the audit log for sharing events
      1. In the Security & Compliance Center, run a PowerShell search:
              Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-30) `
                                   -EndDate (Get-Date) `
                                   -Operations SharingSet `
                                   -ResultSize 5000 |
                ForEach-Object {
                  $data = ($_ | ConvertFrom-Json -PropertyName AuditData).AuditData
                  [PSCustomObject]@{
                    User     = $data.UserId
                    FileUrl  = $data.ObjectId
                    SharedWith = $data.TargetUserOrGroupName
                  }
                } |
                Export-Csv -Path "C:\Reports\ExternalSharingAudit.csv" -NoTypeInformation
        
      2. The FileUrl field in the output is the full link to the shared item.

    Please let me know if you need any help running these commands or if there’s another scenario—happy to assist further.

    Kind regards,

    Finn Dang

    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.