Author Posts

July 5, 2017 at 5:47 am

Hi,

I'm trying to automate the exporting process of a particular mailbox to PST, so I created this simple script:

$Firstdayofthismonth = Get-Date -day 1 -Hour 0 -Minute 0 -Second 0
$Firstdayoflastmonth = (Get-Date -day 1 -Hour 0 -Minute 0 -Second 0).AddMonths(-1)

New-MailboxExportRequest -Mailbox "UserMailbox" -FilePath "Path to the PST" -ContentFilter {(Received -lt $Firstdayofthismonth) -and (Received -ge $Firstdayoflastmonth)}

the idea is, after the end of one month the script would run and export last-one-month worth of emails to PST, but when I ran the script for testing, it exported the entire mailbox rather than only last month, maybe the -contentfilter parameter doesn't accept variables?

Can anyone help?

Thanks

July 5, 2017 at 9:20 am

Hi

Seems like your dates are not correct. First google site: https://thoughtsofanidlemind.com/2011/10/21/date-range-exports-with-new-mailboxexportrequest/ says following

New-MailboxExportRequest -ContentFilter {(Received -lt '04/01/2010') -and (Received -gt '03/01/2010')} -Mailbox "Pelton" -Name DPeltonExp -FilePath \\ExServer1\Imports\DPelton.pst

Regards

Jarkko