Posting the code you're using would be a good idea.
I know nothing about SharePoint, but I posed the question to Microsoft's CoPilot and it gave me this code:
$libraryName = "<your-library>"
$items = Get-PnPListItem -List $libraryName -PageSize 1000
$cutoffDate = (Get-Date).AddDays(-180)
foreach ($item in $items) {
$sharingLinks = Get-PnPFileSharingLink -Identity $item.Id
foreach ($link in $sharingLinks) {
if ($link.Scope -eq "External" -and $link.Created -lt $cutoffDate) {
Write-Output "Item: $($item.FieldValues.Title), Link: $($link.Url), Created: $($link.Created)"
}
}
}
Now, whether that works or not, I don't know. I know that I'd change the code (a little bit) to
$libraryName = "<your-library>"
$cutoffDate = (Get-Date).AddDays(-180).Date
$CsvFile = "C:\Temp\ExternalLinks.CSV"
Get-PnPListItem -List $libraryName -PageSize 1000 |
ForEach-Object |
Get-PnPFileSharingLink -Identity $_.Id |
ForEach-Object {
if ($_.Scope -eq "External" -and ($_.Created).Date -lt $cutoffDate) {
[PSObject]@{
Item = $_.FieldValues.Title
Link = $_.Url
Created = $_.Created
}
}
} | Export-CSV $CsvFile -NoTypeInformation
That same code will identify the links in your team sites library. The link for guests will be made in the "Documents" folder of the team site.