New-MailboxExportRequest Mishandles Dates with Content Filter
So I have been testing the New-MailboxExportRequest cmdlet in Exchange 2010 quite a bit as of late, and have run across some odd behavior in my environment.
Basically it has to do with storing dates in a variable, and then using the variable in the script. So for example this works (as in exports only items from the 3rd and 4th of November 2011)...
PS> New-MailboxExportRequest -ContentFilter {(Received -gt '11/02/2011') -and (Received -lt '11/05/2011')} -Mailbox "useralias" -FilePath "\\server\share\file.pst"
However if I instead declare the variables first...
PS> $begin = '11/02/2011'
PS> $end = '11/05/2011'
PS> New-MailboxExportRequest -ContentFilter {(Received -gt $begin) -and (Received -lt $end)} -Mailbox "useralias" -FilePath "\\server\share\file.pst"
Then it ends up exporting the users entire mailbox (instead of just received on November 3rd and 4th). When I look at the export request.
PS> Get-MailboxExportRequest | Get-MailboxExportRequestStatistics | select *
I end up seeing that the ContentFilter is showing (Received -ne $null), where as on the first one shows the same ContentFilter as I had requested.
Now I thought maybe it had something to do with the data being a string, instead of DateTime, so I tried converting the strings to DateTime with the following commands, although that did not resolve the issue either.
PS> [datetime]::ParseExact($begin,"MM/dd/yyyy",$null)
PS> [datetime]::ParseExact($end,"MM/dd/yyyy",$null)
Anyone have any thoughts? Is this a known bug, an unknown bug, or perhaps just some sort of stupid typo or misunderstanding about powershell?
-matt
If this post is helpful, please mark it as such.
November 7th, 2011 9:04am
Hi
run:
$a= ‘11/02/2011’
New-MailboxExportRequest -ContentFilter “Received -gt ‘$a’”
-Mailbox "useralias" -FilePath \\server\share\file.pst
It works on my server.
Free Windows Admin Tool Kit Click here and download it now
November 8th, 2011 11:21am
Ahh that solves my problem almost completely.
The rest of the solution is here...
PS> $begin = '11/02/2011'
PS> $end = '11/05/2011'
PS> New-MailboxExportRequest -ContentFilter "(Received -gt '$begin') -and (Received -lt '$end')" -Mailbox "useralias" -FilePath "\\server\share\file.pst"
If this post is helpful, please mark it as such.
November 8th, 2011 11:33am