I've spent several hours trying to find a way to use Power Automate to set the default retention label on a SharePoint library (or lits).
I've found a way to automate & set on list items, but I want to set default on library/list:
https://www.gravityunion.com/blog/2021/5/automate-retention-in-microsoft-office-365
as of 3 years ago, looks like people were asking for this:
just thought to ask if this is possible
I know this can be done via CSOM and Pnp, but could not find way to do it using Power Automate.
I was looking for a solution too. I have found an article that explains how to perform this action using different methods. Tested it myself with SharePoint REST API, and it works:
This is my working request:
Note that you need to fill in the ABSOLUTE (not relative) URL of the list/document library as shown in the image.
Hope this helps, for me it did 🙂
Is there a label already applied? I think the SyncToItems only works when the label is null/not set. Also, I noticed some times it takes several minutes for the label to apply, I'm guessing a scheduled job in the background runs?
Hi jherschel7,
I am trying below script for applying labels. Under settings Label is getting applied in drop down but Check box (Apply label to existing items in the library.) is not getting selected.
Also I used in script -BlockDeletion $true -BlockEdit $true, it is not applying. After below script if I tried to get Label then still it shows False as Output:
The label '30 Years Delete' is set to the specified list or library.
Block deletion: False
Block editing: False
Script I used:
$siteURL=Sample Site"
Connect-PnPOnline -Url $siteURL -UseWebLogin
Get-PnPLabel -List "InputList" -Verbose
Set-PnPLabel -List "InputList" -Label "30 Years Delete" -SyncToItems $true -BlockDeletion $true -BlockEdit $true
Kindly let me know do I need to add any commands.
PS - you will need to have installed the PnP SharePoint modules
Run this on the list/library
Set-PnPLabel -List "Documents" -Label "LabelName" -SyncToItems $true #TRUE sets existing items to label
Hi jherschel7,
Thank you very much for sharing the scripts. This is for existing items.
If in list/library new items added then for those items also Retain Policy should be apply.
How to achieve this for new items?
Thanks,
Harish Patil
Here is the script I used, please test on a test site/library before running in PROD!
#COMMENTS: PLEASE TEST ON A TEST SITE, RUN AT YOUR OWN RISK!
$siteURL = "YourSharepointSiteUrl"
$libName = "Documents"
$Label = "YourLabelName"
$count = 0
#Connect to Site
Connect-PnPOnline -Url $siteURL -Interactive
#Get All List Items matching given query
$ListItems = Get-PnPListItem -List $libName -PageSize 500 | Where {$_.FileSystemObjectType -eq "File"}
#Loop through each Item
foreach($ListItem in $ListItems)
{
#UNCOMMENT OUT BELOW AFTER TESTING
#Set-PnPListItem -List $libName -Identity $ListItem.ID -Label $Label
$count++
}
Write-Host "files updated:" $count
Hi Jon.
Kindly let me know what is the script you use? I have the same requirement to apply labels on all list and libraries. Also on all items.
I tried with PowerShell tag Get-PnPComplianceTag but this is not able to find. Getting below errors. Kindly help me how to resolve this issue.
Get-PnPComplianceTag : The term 'Get-PnPComplianceTag' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
Thanks, I ended up writing a PowerShell Script to update on all files in a library where it wasn't already set.
Jon
Create a folder. Then, put a retention label on it and copy every file into it.
The retention label will be shared with every file inside it. The problems is that you can't manage retention label for a special file. Every file of the folder will have the same retention label.
WarrenBelz
146,522
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,890
Most Valuable Professional