Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help with Exchange 2010 powershell syntax

Posted on 2013-06-27
3
Medium Priority
?
592 Views
Last Modified: 2013-06-27
I use a script that exports every mailbox to a PST for temporary backup reasons This currently works:

foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -ContentFilter {(Received -lt "04/21/2013")} -FilePath "\\filesserver\PST\$($i.Alias).pst" }


I am trying to figure out a way so I don't have to manually change the date in the received later than switch. Just testing, I was able to get this to work:

$date=get-date
$startdate=$date.addmonths(-3)
New-MailboxExportRequest -mailbox testuser-contentfilter "Received -gt '$startdate'" -filepath \\fileserver\PST\testuser.pst

So I tried this script:

$date=get-date
$startdate=$date.addmonths(-3)
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -ContentFilter {(Received -lt '$startdate')} -FilePath "\\fileserver\ExmergePST\$($i.Alias).pst" }

I get this error:

The provided ContentFilter value is invalid. ContentFilter is invalid. The value "$startdate" could not be converted to
 type System.DateTime. --> The value "$startdate" could not be converted to type System.DateTime.
    + CategoryInfo          : InvalidArgument: ((Received -lt '$startdate'):String) [], ContentFilterInvalidPermanentE
   xception
    + FullyQualifiedErrorId : DD0301EC

 I've tried different syntax changing the delimeters with no success. Any help would be gretly appreciated. Thanks
0
Comment
Question by:Mark Lewis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39281913
Remove the single quote and try..
-ContentFilter {(Received -lt $startdate)}

Open in new window

Single quotes will not expand variables in PowerShell, double quotes will..
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39281968
Further, the difference between
  -ContentFilter {(Received -lt $startdate)}
and
  -ContentFilter {(Received -lt "$startdate")}
is that the latter will use a string representation of the date - which might lead to errors or unwanted behaviour (the rules for implicit type transformations are complex). The former allows to provide the var contents as DateTime object, which is best.
0
 

Author Closing Comment

by:Mark Lewis
ID: 39282060
That did the trick
0

Featured Post

WEBINAR - Latest Cyber Tips for Defense

Join the WatchGuard Threat Research Team on October 26th for an informative webinar featuring expert tips and tricks for defending your organization from today's latest cyber threats. Don't leave yourself vulnerable to attack. Register for the webinar today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question