This is it. Using this cmdlet how do i clear the mailbox after the export please?
Printable View
export-Mailbox has a -DeleteContent parameter which I think, deletes all the content after the export. It has been a while since I ran this, so double check before running.
I am trying to build this script in 2010 SP2, so have managed to adjust the command to use the new New-MailboxExportRequest but they have deprecated the -deletecontent command and moved it seemingly to the Search-Mailbox command. Which is all well and good for single operations.
How do I mix this up into a script, as I assume if i call the first command and then the second, it wont wait for the export and just delete it all!
Any help appreciated, I just want to export our journal mailbox out to pst once a month, and then clear down the mailbox. I thought about doing one command one day and then the other the next, but I'm always going to have some tween mails that happen between each command.
This is doing my head in!
Thanks
James
@CAWJames Im sure we can help, please can you post the code for the script. If you dont mind i might "borrow" it :)
After some long hours running around the more 'codier' parts of the net, I have a solution:
$dtoday = get-date -format "dd-MM-yyyy"
New-Item \\srv-id-009\MonitorArchive$\$dtoday -type directory -Force
New-MailboxExportRequest -Mailbox Email_journal_user -FilePath \\srv-id-009\MonitorArchive$\$dtoday\$dtoday.pst
while ((Get-MailboxExportRequest -Mailbox Email_journal_user | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"}))
{
sleep 60
}
Get-MailboxExportRequest -Mailbox Email_journal_user | Remove-MailboxExportRequest -Confirm:$false
Get-Mailbox -ID Email_journal_user | Search-Mailbox -SearchQuery 'subject:"*"' -deletecontent -force
Both parts with a while loop in the middle. It still left about 17 emails in the box afterwards, but they are probably just things archived after the fact and the odd bit not covered by -SearchQuery 'subject:"*"'.
Bold bits are the bits to change as they point to my system.
Thanks, and hope this helps others,
James