Hi @Hsaniba,You could try following powershell to retrieve the audit log data and filter for file access events to get the last consultation date for each file in your chosen library.
Connect-PnPOnline -Url "https://your-sharepoint-site" -UseWebLogin
$libraryUrl = '/sites/YourSite/LibraryName/'
$auditData = Get-PnPAuditLog -Query "<Query><Where><And><Eq><FieldRef Name='FileDirRef'/><Value Type='Text'>$libraryUrl</Value></Eq><Eq><FieldRef Name='Event' /><Value Type='String'>View</Value></Eq></And></Where></Query>"
foreach ($entry in $auditData) {
$fileUrl = $entry.ItemUrl
$lastAccessedDate = $entry.Occurred
Write-Host "File URL: $fileUrl, Last Consultation Date: $lastAccessedDate"
}
Here is the document for more details
https://pnp.github.io/powershell/cmdlets/Get-PnPAuditing.html
https://pnp.github.io/powershell/cmdlets/Get-PnPUnifiedAuditLog.html
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.