Forum Discussion
ellan1537
Nov 27, 2023Iron Contributor
Replace existing retention labels on emails
There are tons of emails in multiple users outlook (M365) on which Retention Labels were applied. We've came up with a new set of retention labels now. Is there a script that can remap all the ex...
- Feb 01, 2024After going over this with my team and Microsoft, seems like there is no option to do this exactly that way. Although, you could use the Purview’s Content Search to get a report on Retention labels applied in Exchange.
These are the M365 Retention Labels, not MRM tags.
VasilMichev
Nov 27, 2023MVP
How were the labels applied in the first place? And are we talking about M365 retention labels or (legacy) Exchange retention tags?
- ellan1537Nov 27, 2023Iron ContributorTalking about M365. Retention labels are available to users to manually apply on their emails.
These retention labels are configured in Purview portal- VasilMichevNov 28, 2023MVPUnfortunately, you cannot use the auto-apply functionality for retention labels, as it only works against messages in transit. However, you should be able to programmatically apply the new label via EWS. Here's a sample script: https://learn.microsoft.com/en-us/archive/blogs/akashb/stamping-retention-policy-tag-using-ews-managed-api-1-1-from-powershellexchange-2010
- ellan1537Nov 29, 2023Iron ContributorI'm looking for the script for Exchange Online version. Can you please review and let me know if the below script is appropriate (just for 1 mailbox)?
# Connect to Exchange Online
Connect-ExchangeOnline
Connect-IPPSSession -UserPrincipalName "yourUPN"
# Specify the user mailbox and the old/new retention labels
$userMailbox = "email address removed for privacy reasons"
$oldRetentionLabel = "OldRetentionLabel"
$newRetentionLabel = "NewRetentionLabel"
# Get all items in the user's mailbox with the old retention label
$items = Search-Mailbox -Identity $userMailbox -SearchQuery "RetentionLabel:$oldRetentionLabel" -EstimateResultOnly $false
if ($items.Count -gt 0)
{
# Apply the new retention label to each item
foreach ($item in $items)
{
Set-RetentionCompliancePolicy -Identity $item.Identity -RetentionCompliancePolicy $newRetentionLabel
Write-Host "Updated retention label for $($item.Subject) in mailbox $userMailbox."
}
}
# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false