PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,941 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Shared with External users report - how to get the actual links
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:
Install-Module PnP.PowerShell
Connect-PnPOnline -Url https://<your-tenant>-admin.sharepoint.com -Interactive
$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
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
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