Exporting a companies email with exchange 2013

Welcome Forums General PowerShell Q&A Exporting a companies email with exchange 2013

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
4 years, 3 months ago.

  • Author
    Posts
  • #18585

    Participant
    Points: 0
    Rank: Member

    Hey Folks!

    I've been tasked with a small project to export an entire companies email from 8/11/14 – 8/27/14. The current issue I'm running into is mainly the date range. I'm not sure how to properly format the date ranges so powershell can understand.

    Here's what I've go so far:

    $mailboxes = get-mailbox

    foreach ($mailbox in $mailboxes) {

    new-mailboxexportrequest -mailbox $mailbox -ContentFilter {(Received -lt '08/11/14') -and (Received -gt '08/27/14')} -FilePath \\server\share\$mailbox.pst }

    The company is only about 30 users big, so I'm not too concerned with the get-mailbox command being a "time constraint".

    Thanks for any input!

  • #18586

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Zack,

    Try to use [datetime]'2014-08-11' and [datetime]'2014-08-27' instead of the US date format.

    Regards
    Daniel

  • #18597

    Participant
    Points: 0
    Rank: Member

    This is what I've changed it to:

    $mailboxes = get-mailbox

    foreach ($mailbox in $mailboxes) {

    new-mailboxexportrequest -mailbox $mailbox -ContentFilter {([datetime]'2014-08-11') -and ([datetime]'2014-08-27')} -FilePath \\server\share\$mailbox.pst }

    This failed, it couldn't find the [datetime] parameter.

    However, for giggles, I tried my original script. It "works"!

    The PST exports for everyone's mailbox, but it only contailts emails on both of those dates. So I need to adjust my original script to pull emails through a date, not on one date and another.

  • #18644

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Sorry. What I've actually meant was to replace only the date in your command like below:

    $mailboxes = get-mailbox
    
    foreach ($mailbox in $mailboxes) 
    {
      new-mailboxexportrequest -mailbox $mailbox -ContentFilter {(Received -gt [datetime]'2014-08-11') -and (Received -lt [datetime]'2014-08-27')} -FilePath \\server\share\$mailbox.pst
    }
    

    Edit:
    I think the content filter in your original code is excluding the date range you're looking for. Your filter is looking for emails received before (-lt = lower than) and after (-gt = greater than) but not in the specified date range.

  • #18648

    Participant
    Points: 0
    Rank: Member

    So after working with my manager this afternoon, we were able to find the flaws!

    We found that I had my -ge than and -le in the wrong place. He also helped me organize the script for better read ability. See below:

    $mailboxes = get-mailbox

    foreach ($mailbox in $mailboxes) {

    new-mailboxexportrequest -mailbox $mailbox `
    -ContentFilter {(Received -ge '08/11/14') -and (Received -le '08/27/14')} `
    -FilePath \\Server\Share\$mailbox.pst

    }

    It's always a blast to sit down and really churn over the code with another colleague.

    Cheers!

The topic ‘Exporting a companies email with exchange 2013’ is closed to new replies.