Articles in the "Retention tag on default folder items" series
- Use EWS to apply retention policy to items in a default folder
- Script to set retention tag on default folder items updated to v1.1.1
- Default folder retention tag script updated to 1.3
- Updated script that applies retention tag to items in a default folder [This article]
Edit 12/1/17: The issue with the retention tag GUID not being set by Exchange Online has been resolved. Therefore, I have removed the code that distinguishes between online and on-premises so that the GUID is always applied.
My script that adds a personal tag to items in a default folder stopped working correctly recently. Even though it was applying a tag to matching items, the collection size was never getting smaller. After investigating, I found that a change has been made in Exchange Online. The property that holds the GUID of the applied tag is no longer used by Exchange Online. This is also the property I am using to search for items to tag. You can tell Exchange to set a value for the property, and it will respond without error, but it doesn’t actually update the property. So my script kept getting items that had already been updated. I suspect this has something to do with added support for labels from the Security and Compliance Center.
I have updated the script to instead filter items that do not have a retention period set. To accommodate this distinction from how Exchange on-premises still operates, I have added the Environment parameter, which defaults to Exchange Online, so that the GUID will still be applied when run against an on-premises mailbox. The code that handles changed result sets (where the number of items in the results changes while in the middle of processing) had a display issue where it would double the number of items processed (it didn’t affect the items, but was only a display issue); I have changed the processing loop to now retrieve all items first, then process them in one batch, rather than retrieving and processing them in 50-item batches.
Set-DefaultFolderItemsTag.ps1 (9.4 KiB)