Help with Exchange Powershell

We're running Exchange 2010 SP1. Per our legal department's mandated email retention policy, I have to purge every mailbox at the quarters end of anything older than the end of the previous quarter. Before I do a purge, I also run a mailbox export against the same date range and save it off to a PST which the users have no/little access to, these are archived for 1 year.

In Exchange 2003 this was very easy to do by using ExMerge. Now that our Exchange 2010 migration is complete, I'm stuck using powershell to complete this task. I split it up into 2 scripts, one for the archive and one for the purge. Here are the 2 scripts:

Archive:

$mailboxes = get-mailbox -Database DB1

foreach ($mailbox in $mailboxes) {

    new-mailboxexportrequest -ContentFilter {(Received -ge '01/01/2000') -and (Received -le '03/30/2013')} -mailbox $mailbox -FilePath "\\storage\Email Retention\2013Q2\$mailbox.pst"

}

Purge:

get-mailbox -database DB1 -resultsize unlimited | Search-Mailbox -SearchQuery "Received:> $('01/01/2000') AND Received:< $('03/30/2013') kind:email not kind:contacts not kind:tasks not kind:meetings AND sent:> $('01/01/2000') AND sent:< $('03/30/2013')" -DeleteContent

Does anyone know of a better way to do this? It takes forever to complete, I felt that it went much smoother with ExMerge. Unfortunately setting up a retention policy will not work because we need to be very specific with the date ranges.

Also with the purge script that I have posted above, can anyone tell me what all the object names are for using the kind: and not kind: options. If users have created a local Contact Group, using the contacts option does not include these, I found that out the hard way. I have had a heck of a time finding any documentation on this.

Posted Aug 1, 2013, 5:31 PM UTC

56
Krunk_Fu{e0dc1c29-89c3-4034-b678-e6c29d823ed9}•

Prior to E2010 SP1 you could have done this all in one line, with the -deletecontent on the new-mailboxexportrequest but that has been depreciated.

As much as I want to question the decisions, I'm not. But I want to suggest journaling, it may be an option for you as there is no telling how many messages are deleted during the quarter that your users are deleting that you are not capturing. http://technet.microsoft.com/en-us/library/aa998649(v=exchg.141).aspx

2
urvon•

Take a look at managed folders and messaging records management. If possible, look into changing the policy to a rolling 90 day window vs. the quarter based blocks (or whatever is really appropriate to your situation). That way the exchange system will automatically delete emails that are older than 90 days on a continuous basis.

If nothing else, you should be able to use managed folders and change the policy retention dates to match what you are looking for and let the exchange services handle purging the messages.

2
CraptainCrunch•

You could just use a customized Retention Policy which is set on the Exchange server. That would be by far the easiest way to tackle this.

1
dindenver•

UKDKBR, I was able to slightly accelerate my mailbox exports by balancing them across multiple CAS servers. It is important to understant that these exports are actually entirely performed by the CAS. The mailbox server just serves up mail as if it iwere an outlook or OWA request. It uses the same service that manages mailbox moves and database replication, so those activities might interfere with the exports as well. To modify your code slightly, try this:

$mailboxes = get-mailbox -Database DB1

foreach ($mailbox in $mailboxes) {

$MRS=(Get-TransportServer | Get-Random).name
new-mailboxexportrequest -ContentFilter {(Received -ge '01/01/2000') -and (Received -le '03/30/2013')} -mailbox $mailbox -FilePath "\\storage\Email Retention\2013Q2\$mailbox.pst" -MRSServer $MRS

}

Although, as mentioned, this might be better replaced with a retention policy and journalling. Dave M

1
ukdkbrOP•

Thanks for the suggestion, sadly i'm dealing with a single multi-role Exchange server.

1
dlayknee•

Does anyone know of a better way to do this?

I don't know that re-working the powershell code would provide you any faster a solution - the heavy lifting of this task is done by the Exchange server itself not PS.

can anyone tell me what all the object names are for using the kind: and not kind: options

That's actually Windows search syntax which you can read about on MSDN here: http://msdn.microsoft.com/en-us/library/aa965711(v=vs.85).aspx

Edit: this is a perfectly valid place to ask this, but in the future be aware that you can also use r/PowerShell for scripting help as well!

0