Post Migration Scripts for O365 – Part 2 Set Retention Policy and Retain Deleted items from a csv file

When migrating users to O365, you may need to set a group of users or specific users Item Retention and Deleted Item retention policies. If you have a list of users who need specific settings you can run the following command against the list to only apply the desired settings to those users. You will need to connect to O365 to run these scripts for O365 Users.

### This script will list all users in a csv file who have a Deleted Items retention setting if 14 Days and change it to 30 Days.

Import-CSV "C:\UKUsers.csv" | %{Get-Mailbox -identity $_.UserPrincipleName | where {$_.retaindeleteditemsfor -eq "14.00:00:00"} | Set-Mailbox -RetainDeletedItemsFor "30.00:00:00"}

### This script will search for users in a csv file who have a particular Retention Policy assigned and set it to another policy.

Import-CSV "C:\UKUsers.csv" | %{Get-Mailbox -identity $_.UserPrincipleName | where{$_.RetentionPolicy -eq "Incorrect Policy Name"} | Set-Mailbox -RetentionPolicy "Correct Policy Name"}
Facebooktwittergoogle_pluslinkedinby feather

Leave a Reply

Your email address will not be published. Required fields are marked *