2010 Powershell Scripts to Manage Archive Mailboxes
I need to come up with 2 PowerShell scripts that run against Archive mailboxes. So far I have spent a couple of days working on this, and I have become a bit frustrated. I need one PowerShell script that locates all attachments inside the Archive mailbox (I have a separate database that houses the Archive mailboxes). The reason for this is that our storage policy states we cannot store attachments with the e-mails when archiving them. So I would need to be able to generate a list of mailboxes, and possibly messages so that they can clean up the attachments. Or better yet if there is a way to block attachments completely from being dragged into the Archive. The second PowerShell script will need to delete all messages over 5 years old from the Archive mailbox. I have a RPT that will clean out messages older than 90 days from the Inbox, but I need to be able to clean out all messages over 5 years from the Archive mailbox. The reason for this is we have a policy for legal purposes to delete all e-mails over 5 years old (unless put on litigation hold). I thought that I could use export-mailbox to do this, but after a bit of research I have found that export-mailbox has been deprecated for mailbox-search or new-mailboxsearch. I have found that I can do a delete if I use mailbox-search, but I am unable to put in a date range or max age. I found that if I use new-mailboxsearch then I can put in a date range, but I cannot delete the messages. The problem is that I am not sure if I can pipe the results from new-mailboxsearch into mailboxsearch. Also I did not find a way to just search the Archive mailbox, both of those search either the Inbox, or the Inbox and the Archive mailbox. The last problem that I ran into was that both of them have the ability to search Attachments, but I did not find a way to search for attachments. I apologize, this was my first attempt at playing with PowerShell, and I have become quite frustrated with trying to find what cmdlets to use when, and how they work. The next problem was I kept finding solutions for Exchange 2007, but they are not used Exchange 2010 SP1. I thought this would be fairly simple but I think I was wrong. Any help would be greatly appreciated.
May 2nd, 2011 11:02pm

Okay, I figured out how to do the search for the attachments. New-MailboxExportRequest -Mailbox "KTest2@Contoso.com" -IsArchive -ContentFilter {Attachment -like "*.*"} -FilePath "\\server\c$\users\contoso\test.pst" I have a little bit more to do with that, but for the most part it is there. I could also do HasAttachment $true for the attachment search, which I will need to test, and then probably use. The problem that I have now is that I have not found a way to handle the deletion of messages from the Archive. I am able to do a delete of messages from the mailbox, including the Archive, by using Search-Mailbox -Identity KTest2@Contoso.com -DeleteContent. The problem is that I cannot specify a date range, the closest I can come is the -SearchQuery SentDate. I tried using the ContentFilter syntax from New-MailboxExportRequest to try and specify a date or a date range, but they kept returning 0 results. Search-Mailbox -SearchQuery {(Received -lt '04/13/2011') -and (Received -gt '04/15/2011')} -Identity "KTest@contoso.com" -EstimateResultOnly On the flip side of things I am able to use New-MailExportRequest and build the query that I need to find all the e-mails that need to be deleted. But there is no delete switch for that cmdlet. Is there anyway for me to pipe the results from New-MailboxExportRequest into Search-Mailbox? Search-Mailbox requires an identity, but is there a unique identifier for individual e-mails that I can pass to it? I am really annoyed with Microsoft that they removed the Export-Mailbox command as it has all the switches rolled into it, so I could do what I needed to do. I understand why they removed it, and how the new cmdlets are better, but I think it is dumb that they killed off the functionality of Export-Mailbox. Although I could be incorrect in these statements.
Free Windows Admin Tool Kit Click here and download it now
May 5th, 2011 12:05am

In the end I found that the information I was given about how policies work in Exchange 2010 was incorrect, and that I am able to apply retention policies to Archive folders. So this has resolved my PowerShell problem. I am now able to search for attachments in the Archive, and I am able to remove aged e-mails from the Archive. I am still curious if there is another way to handle this through PowerShell, but my problem has been resolved.
May 9th, 2011 5:03pm

How can one apply a retention policy to archive folders? Is it possible to have a policy to archive after 3 months and also have a policy to delete after 7 years? Thanks,
Free Windows Admin Tool Kit Click here and download it now
March 16th, 2012 8:58pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics