• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2703
  • Last Modified:

New-MailboxExport with a foreach

I am trying to export mail in a certain date range for ALL mailboxes.  I found a command and modified it to include the contentfilter.

(By the way, I have noticed this ONLY works in american date format, WHILE the machine has its date format in the same american format, any other combination does not work)

Here is the command I am using

foreach ($i in (Get-Mailbox)) {New-MailboxExportRequest -Mailbox $i -contentfilter {(Received -
lt "03/23/2011") -and (Received -gt "04/18/2011")} -FilePath "\\svr01\e$\mailtemp\date-range.pst"

When I press enter it simply drops down to another prompt that looks like this:
>>
Pressing enter simply brings up a new blank line with
>>

It never does anything else and eventually I CTRL+C out of it

How can I make this command work?  I can do the command without the foreach, and specify the mailbox name myself and that works.



0
VisitsTech
Asked:
VisitsTech
  • 6
  • 4
1 Solution
 
VisitsTechAuthor Commented:
I have found that I missed a bracket, which is now fixed. Still have a problem though..

This is the new command

foreach ($i in (Get-Mailbox)) {New-MailboxExportRequest -Mailbox $i -contentfilter {(Received -
lt "03/23/2011") -and (Received -gt "04/18/2011")} -FilePath ""\\svr01\e$\$($1.alias.pst)"}

It now gives the return:
The server or share name specified in the path may be invalid, or the file could be locked.
    + CategoryInfo          : NotSpecified: (0:Int32) [New-MailboxExportRequest], RemotePermanentException
    + FullyQualifiedErrorId : 3846AD3C,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest

Once for every mailbox
I have ensured that the server path is correct.

0
 
PostmasterCommented:
Would it not be easier to run Exmerge on another box (32-bit) and just fill in the dates and details?
0
 
PostmasterCommented:
This MS link deals with the exporting of mail from mailboxes using date / subject key values
http://technet.microsoft.com/en-us/library/bb266964(EXCHG.80).aspx

It may help with your problem.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
VisitsTechAuthor Commented:
Hi Postmaster, Your first comment is something I considered. but Since I am now supporting over 30 servers with 2010 SP1 I should really just get this command (or something similar working).   In any case, I can manually type in all the names should it come to that, but I want to get an automated method working.

Your second comment is less useful as it refers to Server 2007, which had different commands that no longer apply for exporting mailboxes.
0
 
PostmasterCommented:
In your command you have:
{(Received -lt "03/23/2011") -and (Received -gt "04/18/2011")}

How can you any mail have a date LESS than 03/23 AND GREATER than 04/18?

surely it should be:
{(Received -Gt "03/23/2011") -and (Received -Lt "04/18/2011")}
0
 
VisitsTechAuthor Commented:
I believe you are correct, as I probably would have found if the command would just work hehehe.

This is the new command:

foreach ($i in (Get-Mailbox)) {New-MailboxExportRequest -Mailbox $i -contentfilter {(Received -Gt "03/23/2011") -and (Received -Lt "04/18/2011")} -FilePath ""\\svr01\e$\$($1.alias.pst)"}

But I still just go to a >> prompt
0
 
VisitsTechAuthor Commented:
I know the double greater than symbol means it is waiting for more information, but I am unsure what it wants... I am guessing there is a syntax error, but all other examples I have found have the same syntax
0
 
PostmasterCommented:
You have 2x double quotes after -FilePath
0
 
VisitsTechAuthor Commented:
Postmaster, thanks that fixed That problem so I will attribute the points.

Still having a problem though, which is that the part that is supposed to write the PST with the mailbox name is not working :(

Oh well, at least I am a lot closer...
0
 
VisitsTechAuthor Commented:
The solution provided answered my question
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now