web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Is there a way to set ...
Power Automate
Unanswered

Is there a way to set the Retention Label at document library level with Power Automate?

(0) ShareShare
ReportReport
Posted on by 72

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:

https://powerusers.microsoft.com/t5/Power-Automate-Ideas/Get-and-Set-Compliance-Labels-in-SharePoint/idi-p/156112 

 

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.

Categories:
I have the same question (0)
  • jherschel7 Profile Picture
    27 on at

    Following up on this?  Put in a ticket with MS, but they said it is out of scope.  Anybody know of a way to update the _ComplianceTag field for items via PowerShell or Power Automate?   We have large libraries with thousands of items using the old Retention Policy and we are migrating to Modern SharePoint using the new M365 policies via Retention Label...

  • jherschel7 Profile Picture
    27 on at

    anybody?

  • Community Power Platform Member Profile Picture
    on at

    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. 

  • jherschel7 Profile Picture
    27 on at

    Thanks, I ended up writing a PowerShell Script to update on all files in a library where it wasn't already set.

     

    Jon

  • hspatil31 Profile Picture
    24 on at

    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.

  • jherschel7 Profile Picture
    27 on at

    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
  • hspatil Profile Picture
    8 on at

    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

  • jherschel7 Profile Picture
    27 on at

    Run this on the list/library

    Set-PnPLabel -List "Documents" -Label "LabelName" -SyncToItems $true #TRUE sets existing items to label
  • jherschel7 Profile Picture
    27 on at

    PS - you will need to have installed the PnP SharePoint modules

  • hspatil Profile Picture
    8 on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard