Export email to PST based on specified subject for all mailboxes using -ContentFilter Entered via a Read-Host variable

I am attempting to recreate what we have done previously using exmerge under Exchange 2003 where we can archive out specific emails based on subject to pull out 0 days spam etc.  What I want to do first is to copy the mails to an individual .pst per
user (in case we need to pull any emails back)
I have manged to do this with using the following command (in this example extracting a subject containing the sub-phrase junktest):
foreach ($mbx in (Get-Mailbox | Where {$_.ExchangeVersion.ExchangeBuild.Major -eq 14})) {New-MailboxExportRequest -Mailbox $mbx -ContentFilter {(subject -like "*junktest*")} -FilePath "\\ssf-adm-ex01\mailboxexport\$($mbx.Alias).pst"}
I would like now to simplify the use of this so I am attempting to create a script where the user can input the emails Subject rather than having to edit the code each time.
However I cannot get this to work. Using the following script it just exports emails with a subject line of $subjectstring rather than the variables content
$subjectstring = Read-Host 'Please enter the Subject String'
foreach ($mbx in (Get-Mailbox | Where {$_.ExchangeVersion.ExchangeBuild.Major -eq 14})) {New-MailboxExportRequest -Mailbox $mbx -ContentFilter {(subject -like "$subjectstring")} -FilePath "\\ssf-adm-ex01\mailboxexport\$($mbx.Alias).pst"}
using the following just exports all of the emails from the server
$subjectstring = Read-Host 'Please enter the Subject String'
foreach ($mbx in (Get-Mailbox | Where {$_.ExchangeVersion.ExchangeBuild.Major -eq 14})) {New-MailboxExportRequest -Mailbox $mbx -ContentFilter {(subject -like $subjectstring)} -FilePath "\\ssf-adm-ex01\mailboxexport\$($mbx.Alias).pst"}
I have tried all sorts of  combinations however I cannot get this to work correctly.
Can anyone help a powershll newbie out?  Thanks in advance.

Try:
-ContentFilter "subject -like '$subjectstring'"
No braces.  See what that does for you.
This works like a dream.
Thank you for your help,  it is appreciated.

Similar Messages

  • Exporting incoming email address by date range for all mailboxes

    I run a Small Business 2011 Standard server using Exchange 2010 for a small municipality.  A public records request was made for all email address that emailed any employee of that city between 1-1-2013 and 3-6-2014 .  There are about 160,000 emails
    for that date range but how can I just export a log of the senders email address with a time stamp?  Thank you in advanced for any help you can give.
    I should add that All logging is at defaults values 
    I found a "work around",  I have a Barracuda Message Archiver, I did a search of the date range and exported it to CSV, then imported it in to Excel and just deleted the extra data.
    Thanks for the fast replies 

    Good point, Belinda. If you have that time period within your log retention, then you should be able to do something with the Exchange Shell. This is a bit rough but could serve your purpose:
    #--- This finds the email addresses of the users whose city is set to Sydney.
    $Sydmbx = Get-ADUser -Filter {City -eq "Sydney"} -Properties homemdb, proxyaddresses | ?{$_.homemdb -ne $null}
    $Sydmbx | %{$Sydaddresses += $_.Proxyaddresses}
    $Sydaddresses = $Sydaddresses.TrimStart("SMTP:")
    $Sydaddresses = $Sydaddresses.TrimStart("smtp:")
    #--- Enter your HT servers here
    $ExchServ = @("exch01", "exch02")
    #--- This creates an object which lists senders who have sent to our recipient addresses, the timestamp and messageid.
    $Report =@()
    foreach ($server in $ExchServ){
    foreach ($addy in $Sydaddresses){
    $sentmail = Get-MessageTrackingLog -Server $server -Recipients $addy -Start "01/01/2013 12:00:00 AM" -End "06/03/2014 2:00:00 PM" -EventID Deliver -ResultSize Unlimited
    $sentmail | foreach{
    $Trackobj = New-Object PSObject
    $Trackobj | Add-Member -MemberType NoteProperty -Name "Recipient" -Value $addy
    $Trackobj | Add-Member -MemberType NoteProperty -Name "Timestamp" -Value $_.Timestamp
    $Trackobj | Add-Member -MemberType NoteProperty -Name "Sender" -Value $_.Sender
    $Trackobj | Add-Member -MemberType NoteProperty -Name "MessageID" -Value $_.MessageID
    $Report += $Trackobj
    $Report
    You can change the location to suit yourself as long as you populate "City" in AD and the server names with your own servers.

  • System generated emails - how to include a mandatory prefix for all email

    Good morning.
    I have been asked if there was a way to default a Security Classification into the Subject Line of all SAP system generated emails.
    Examples "[UNCLASSIFIED] Please approve Purchase Order 123456" or "[UNCLASSIFIED] Please approve Absence for Fred Smith".
    I can have the individual code of the Programs that generate the Subject Texts but is there a way to have this default for ALL emails?
    Thanks
    David

    Hi David,
    This one sounds like the one for the Basis guy to look at. They should be able to configure (default) this prefix in the EMAIL/SMTP node(s) as viewed in transaction SCOT. The changes should be done from the IMG (SPRO).
    Regards.

  • How do i export the table data based on some condition for backup

    Is is syntax correct
    exp scott@orcl92 file=emp_29aug.dmp tables=emp
    query=\"where emp_no in (1,2,3,4) \".
    How do i take the backup of more than one table?
    what is the syntax for that
    Thans

    Thanks for your response
    If i want to add more than one condition in the query, then how do i do that
    exp scott/tiger@orcl file=scott.dmp tables=(emp, dept) query=\"where deptno = 30\" and emp_no in (1,2,3,4);
    how do i do that

  • Adding list based menu only once for all related pages

    Hi,
    I have a one level tab application. For a given tab I have 5 different pages. I would like let the end user navigate to these pages via a list region. Currently I have added to all five pages a list region and assigned the same list item to these list regions.
    Is it possible that I add this list based menu only once to my application or this is the normal way of doing it?
    Is there a way to let
    Regards,
    Tamas

    Use page zero.
    Add regions containing the lists for each tab to the same region display point on page zero, making each region conditional using a "Current Page Is Contained Within Expression 1..." condition.

  • Emails in inbox not visible unless searched for after mailbox migration

    Hi,
    After migrating a mailbox from exchange 2010 to 2013 everything looked ok upon first logon. The user then deleted 4 emails which prompted all the emails to disappear that were listed in inbox. They are visible if you do a search within inbox. All new mails
    do show as normal.
    Thanks
    Chris

    Hi Chris,
    Agree with Amit's suggestion. Please check if you can see these emails via OWA. If yes, please use Online mode to verify if Outlook works well. If yes, I recommend you create a new profile to solve this issue.
    If the issue persists, please use Outlook safe mode to determine whether the problem is caused by add-ins.
    Hope it helps.
    Best regards,
    Amy Wang
    TechNet Community Support

  • I get this message when I try to open email: JavaScript must be enabled in order for you to use gmail in standard view. However it seems javascript is either disabled or not supported by your browser. This is new. JavaScript is enabled.

    I am running Windows xp home edition 5.1.2600 and Firefox 3.6.12. I can use gmail in the HTML view, but would prefer the standard view.

    Do you have that problem when running in the Firefox SafeMode? <br />
    [http://support.mozilla.com/en-US/kb/Safe+Mode] <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If not, see this: <br />
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • Order Import failing with error "The specified subinventory is invalid to use, the profile option INV: Allow Expense to Asset Transfer is set to No. Change the profile option to Yes or choose a valid subinventory."

    Hi All,
    I am getting this error while importing an internal sales order.
    “The specified subinventory is invalid to use, the profile option INV: Allow Expense to Asset Transfer is set to No. Change the profile option to Yes or choose a valid subinventory.”
    I have tried to set mentioned profile as ‘Yes’. But still getting same error.
    Also, provided subinventory is present and active in given inventory organization.
    Please share if anybody encountered this before and have a solution.

    Hi 2878342
    Please refer the following metalink note, it should resolve your problem.
    Order Import Interface.Error Message Specified Subinventory Is Invalid To Use (Doc ID 406411.1)

  • Specifying border for h:datatable

    I am trying to specify border for h:datatable using something like this.
    .selDataTable {
         width:100%;
         border:5px;
    }          The problem is that the border appears only on the outside of the table and not for each cells. On the other hand if I directly specify border="5" on the datatable tag, I get borders all arround the table and cells. This is what I want. Why doesn't the class specified by styleClass="selDataTable" provide borders arround each cell.
    regards,
    nirvan.

    So that you can set the border of the table, head, body, foot, rows and cells individually.

  • How do i export emails to excel?

    I am trying to categorize and count emails in Mac Mail.  Is it possible to export emails from Mac Mail into Excel so that I can sort and count based on "sent from" and "date"?  Any help would be greatly appreciated.

    Well, I don't know of any way to do it using Mail or other GUI tools, but it's certainly not impossible with some work in Terminal.  I can easily give you a partial solution. If that's acceptable to you, the following type of commands should help:
    Firstly, you need to open Terminal and change directories into your mailbox folder.  The name of this will depend a bit on the account you are using but it should be something like:
    cd Library/Mail/V2/POP-username@domain
    Then you need to find all the mail files and extract the fields you want:
    find . -type f -name \*.emlx -exec egrep "From:|Return-path:|Subject:|Message-ID"  {} \;
    At this point to put the fields together in one line with a field separator (I wouldn't recommend a comma because the subject might include a comma) would make that command pretty messy I think. However it shouldn't be too hard to take the output and process it.
    Hope that helps get you started.
    Ivan

  • Is there a way to address email (i.e. a word or some code) that would place that email in a specified inbox folder?  not using internal rule, rather the beginning of this sort happening as it comes in?

    is there a way to address email (i.e. a word or some code) that would place that email in a specified inbox folder?  not using internal rule, rather the beginning of this sort happening as it comes in?
    In other words
    I tell a friend if he is emailing me on a particular subject, is there something he can do at his end ([email protected]/research)
    like adding the word research at the end of my eamil address that would tell my inbox to place that in the inbox/research folder?
    If I have to use a rule on my end, then do I tell him to just place the word research in the subjct line and then I write a rule to place anything with the word research in the subject line in my inbox/research folder?
    will the subject line be required to only have the one word research to work, or will the rule look for any presense of that word in the subject line?
    thanks
    eric

    iCloud email supports 'plus' addressing. http://en.wikipedia.org/wiki/Email_address#Address_tags
    So your friend could just add '+research' to the username part of your email address, and you setup a rule at icloud.com to put all emails sent to that address into a particular folder.
    For example:
    [email protected]
    There's no way to do it without rules on the server though.

  • Is there a contact list for my email addresses saved somewhere that I can access all of them and/or export them to a file?

    I would like to find out if there is a address book automatically created for all of my email addresses based on my inbox/outbox. If so, where can I find them and/or is there a way to export them or print a list?
    Please help me!

    Mail > Window > Previous Recipients
    lists those addresses to whom you have sent e-mails

  • Do imported emails from pst files get saved to Exchange Server?

    So I exported a user's email into a pst file and I'm importing all of them into his new email address.  My question is whether these newly imported emails will be only available locally or will they be uploaded into the Exchange server (which is TWC's
    hosted service) and therefore he'll be able to  access them from his phone as well?  If they are not uploaded, how would I go about to making these emails available on his phone through his new email address as well then?

    Hi th0rax,
    yes, if you imported mails from a PST file to the Exchange Mailbox you will be able to Access them from Outlook, OWA and ActiveSync where you habe Access to your Mailbox.
    I suggest you should do that via new-mailboximportrequest (http://technet.microsoft.com/de-de/library/ff607310(v=exchg.150).aspx) if it is a big PST file and maybe a longer
    list of users.
    You can also Import via Outlook but in that case you need to have that Outlook Client running until "All Folders are up to date" and the new Mailbox Content was replicated to your Servers Mailbox after the Import was done.
    Regards,
    Martin

  • How to export mail to pst ?

    Hi, I would like to know the best way to export my mail from a Mac os X to a pst in order to add to an Outlook on a pc ?

    Hi,
    You'll need to configure your Yahoo account in Microsoft Outlook and then export the email folders to .pst file.
    To configure Yahoo email in Outlook, please refer to this:
    https://help.yahoo.com/kb/outlook-sln15165.html
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice.
    Microsoft does not guarantee the accuracy of this information.
    To export Outlook items to a .pst file, please refer:
    http://office.microsoft.com/en-in/outlook-help/export-outlook-items-to-an-outlook-data-file-pst-HA102534110.aspx?CTT=1
    Best Regards,
    Steve Fan
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • OWA 2013 export email

    Hi Team,
    i had a question,
    can OWA 2013 user export email to attachment to local file? 
    like eml format?
    please tell me the guide if available :)
    thanks Team
    Regards

    Hi,
    Based on my knowledge, we can export messages from OWA in Office 365 Exchange Online. But I'm afraid that Exchange 2013 OWA doesn't have this function. Your understanding will be appreciated.
    For your reference:
    Export Email Messages from OWA in Office 365 Exchange Online
    http://blogs.technet.com/b/catastrophic_failure_joannav/archive/2013/09/25/export-email-messages-from-owa-in-office-365-exchange-online.aspx
    Hope this can be helpful to you.
    Best regards,
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
    Amy Wang
    TechNet Community Support

Maybe you are looking for