David-Barrett-MS / PowerShell-EWS-Scripts

A collection of PowerShell scripts that use EWS to perform actions against Exchange mailboxes
MIT License
118 stars 13 forks source link

Merge-MailboxFolders #29

Closed bwlonsdaledxc closed 1 year ago

bwlonsdaledxc commented 1 year ago

Hi, David. I've been tweaking the list of folders that I'm moving into the archive for the users we offboard, but have hit a snag with the Deletions folder. As you (may) recall, we need to shrink the primary mailbox down to as small as possible before we offshore it.

I am almost certain this used to work fine, but can't seem to get it to recognise the Deletions folder anymore. We do occasionally get users who've got a substantial amount of mail in there that is recoverable, so we want to move it out to the archive. When the user is later moved back into M365, we just leave it in the archive and it's permanently gone when we then remove their archive.

Any idea why it can't recognise this folder path? If I do it as part of the full folder collection or specify it separately like below when I have been troubleshooting it's the same error.

image

David-Barrett-MS commented 1 year ago

That log shows that the script couldn't find the source folder. Do you mean Deletions? Deleted Items are stored in Deleted Items, and should be referred to by WellKnownFolderName enumeration (in case of localisation). To move Deleted Items from primary to archive, you could use @{"WellKnownFolderName.ArchiveDeletedItems" = "WellKnownFolderName.DeletedItems" }

https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.wellknownfoldername?view=exchange-ews-api

bwlonsdaledxc commented 1 year ago

Using Get-MailboxFolderStatistics, shows it up as FolderPath FolderType /Deletions RecoverableItemsDeletions

The regular deleted items move across fine, they are /Deleted Items Deleteditems

It's what you see after you've emptied the recycle bin, but they are then available recovery still (for 30 days or so)

https://learn.microsoft.com/en-us/exchange/policy-and-compliance/recoverable-items-folder/recoverable-items-folder?view=exchserver-2019

I will try its well known folder name instead (and also think about dealing with Purges folder!)

David-Barrett-MS commented 1 year ago

Recoverable Items are not under Top of Information store, so will need to be referenced by WellKnownFolderName.

bwlonsdaledxc commented 1 year ago

Thanks, another issue fixed....I'll create a new one for running this as a job next :)