Forum Discussion
JimmyWork
Nov 18, 2022Iron Contributor
Best way to auto apply retention labels to all files in a M365 group
What I want to achive.
Teams are created thrue a script/power auomate.
The Teams generated follow a name standard and always start with XA-"Random numbers"
I want to apply retention labels to all the Teams that start with XA-.
Should I incorporate this in the Teams creation script, so when the Team is created I apply the labels using PowerShell?
Is there any other way to achive this in a good way? I want to retain the team and all the files in it from x amount of years to protect from deletion.
2 Replies
Sort By
- For your existing Team sites you can just add them to the retention policy and wait for them to be crawled by the system. Based on your settings, the items will then get a retention policy assigned.
If you are adding new ones, I would suggest adding code to your script to have them amended into your current scoping as well.
a script that might be usefull for this:
Install-Module PnP.PowerShell
Import-Module PnP.PowerShell
Register-PnPManagementShellAccess
$label = "Your retention label name"
Connect-PnPOnline `
-Url "https://XXXX.sharepoint.com/sites/NAME TEAMS" `
-Interactive
Set-PnPLabel `
-List "Shared Documents" `
-Label $label.Name `
-SyncToItems $true
$items = Get-PnPListItems -List "Shared Documents"
You could also search for event driven retention labels. You could make an event, and everytime that occurs, the label should be applied.- JimmyWorkIron ContributorThank you for answering.
I will look into event driven retention labels and see if this can be used to auto apply the labels also.
For the retention policy i guess there is no auto apply that I can use to specify if the SP site or the 365 Group starts with a certain prefix it should apply automatically?
The PS script will most likly be used if I dont find a better way to auot apply the labels. Thank you again for taking time and answering