locked
New-MailboxExportRequest Mishandles Dates with Content Filter RRS feed

  • Question

  • 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.

    Monday, November 7, 2011 6:04 AM

Answers

  • Hi
       run:
       $a= ‘11/02/2011’
      
    New-MailboxExportRequest -ContentFilter “Received -gt ‘$a’”  -Mailbox "useralias" -FilePath \\server\share\file.pst

    It works on my server.

    Tuesday, November 8, 2011 8:21 AM
  • 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.
    Tuesday, November 8, 2011 4:23 PM

All replies

  • Hi
       run:
       $a= ‘11/02/2011’
      
    New-MailboxExportRequest -ContentFilter “Received -gt ‘$a’”  -Mailbox "useralias" -FilePath \\server\share\file.pst

    It works on my server.

    Tuesday, November 8, 2011 8:21 AM
  • 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.
    Tuesday, November 8, 2011 4:23 PM
  • Thanks

    Suraj Panicker | Microsoft Corp.

    Tuesday, June 21, 2016 12:29 PM
  • This almost solved my problem. But we still have a date issue.

    We have a Exchange Server with the Dutch Region settings. This means the date-notation is set to DD-MM-YYYY

    When using the following command, all mailbox items received in the month July are exported:

    New-MailboxExportRequest <mailbox> -FilePath <share> -ContentFilter "((Received -gt '01-07-2016') -and (Received -lt '01-08-2016'))" -ContentFilterLanguage "nl"

    I checked the exported PST and only the July items exist. So this must be the correct (date) syntax.
    But if I try to set the DD higher than 12, the following happens:

    New-MailboxExportRequest <mailbox> -FilePath <share> -ContentFilter "((Received -gt '01-07-2016') -and (Received -lt '01-08-2016'))" -ContentFilterLanguage "nl"

    The provided ContentFilter value is invalid. ContentFilter is invalid. The value "13-07-2016" could not be converted to type System.DateTime. --> The value "13-07-2016" could not be converted to type System.DateTime.


    Some more date examples and results:

    01-07-2016 - 01-08-2016 Works. All items of July are exported
    13-07-2016 - 01-08-2016 Does not work
    01/07/2016 - 01/08/2016 Works. All items of July are exported
    13/07/2016 - 01/08/2016 Does not work
    07/01/2016 - 08/01/2016 Works, but all items between 7 and 8 January are exported
    07/13/2016 - 08/01/2016 Works, but Failed in queue. (Both contentlanguagefilter to nl or en)

    For me it seems there is a date calculation error somewhere. The export does work fine, but the DD field is somehow somewhere misunderstood as  a month value (?!?)

    Exchange version: Version 14.3 (Build 123.4)

    Hope someone is recognizing this issue.


    • Edited by CreatoX Wednesday, August 3, 2016 7:12 AM
    Wednesday, August 3, 2016 7:10 AM
  • I'm actually seeing this same behavior.  I am not sure it matters a whole heck of a lot what date format you use.  Here in the states, I have tried variables with MM/dd/yyyy and MM-dd-yyyy format.  Using either method, I get the entire mailbox.  If I stop using a variable and hard code the date in the ExportRequest, the export works great.

    This could be a build version problem.  I am using the same build as you.  I am going to install Update Rollup 14 this weekend.  Hopefully that makes a difference.

    Friday, September 2, 2016 4:11 PM