Before you start or create the Retention Policy in the Microsoft 365 compliance, you can use the following script commands to view the original documents information.
Please run the following script in the SharePoint Online Management Shell as admin:
#the specific location path
$SiteURL= "https://testlz.sharepoint.com/sites/Intern1"
Connect-PnPOnline -Url $SiteURL -UseWebLogin
#this script only view a signal Document Lib
$List = Get-PnPList -Identity /doc
write-host "Document Library Name : "$List.Title -ForegroundColor Green
#loop through all files
$ListItems = Get-PnPListItem -List $List | Where {$_["FileLeafRef"] -like "*.*"}
$DocumentsData=@()
ForEach($Item in $ListItems)
{
#Collect Documents Data
$DocumentsData += New-Object PSObject -Property @{
FileURL = $Item.FieldValues['FileRef']
FileID = $Item.FieldValues['GUID']
FileName = $Item.FieldValues['FileLeafRef']
FileDate = $Item.FieldValues['Created']
}
}
$DocumentsData
Then, go to Microsoft 365 compliance page, start your Retention Policy.
======================
@YL
I have updated my Answer.
Please the following steps:
1.Before you start or create the Retention Policy in the Microsoft 365 compliance, you can use PowerShell command to get a Documents Information Report.
Please run the following script in the SharePoint Online Management Shell as admin:
$SiteURL= "https://testlz.sharepoint.com/sites/Intern1"
Connect-PnPOnline -Url $SiteURL -UseWebLogin
$List = Get-PnPList -Identity /doc
$Query = "<View><Query><Where><Lt><FieldRef Name='Created' Type='DateTime'/><Value Type='DateTime'>
<Today OffsetDays='-5'/></Value></Lt></Where></Query></View>"
$ListItems = Get-PnPListItem -List $List -Query $Query
#Collect Documents Data
$Docs=@()
ForEach($Item in $ListItems)
{
$DocsObject = New-Object -TypeName PSObject
$DocsObject | Add-Member -Name 'Library name' -MemberType Noteproperty -Value $List.Title
$DocsObject | Add-Member -Name 'FileID' -MemberType Noteproperty -Value $Item.FieldValues['GUID']
$DocsObject | Add-Member -Name 'FileName' -MemberType Noteproperty -Value $Item.FieldValues['FileLeafRef']
$DocsObject | Add-Member -Name 'FileDate' -MemberType Noteproperty -Value $Item.FieldValues['Created']
$DocsObject | Add-Member -Name 'FileURL' -MemberType Noteproperty -Value $Item.FieldValues['FileRef']
$Docs += $DocsObject
}
$Docs | export-csv "D:\report111.csv"
Then, you can send an Email to notice owners in advance by using Microsoft Flow.
Recurrence [according to the custom value, run periodically] >> Get files(properties only) >> Filter array [get documents information as an array] >> Apply to each >> Condition [select documents that meet conditions. Note that Formula should be consistent with the PowerShell command ] >> (if yes)Send an email notification
Ps: lessOrEquals(formatDateTime(addDays(item()?['Created'], 5), 'MM/dd/yyyy'), utcNow('MM/dd/yyyy'))
Finally, go to Microsoft 365 compliance page, start your Retention Policy.
Thanks,
Echo Du
=============================
If an Answer is helpful, please click "Accept Answer" and upvote it.
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.