locked
Removing specific messages from your with Powershell command: RRS feed

  • Question

  • I have more than 320.000 spam mail in info@xx.com , i want to delete the mails which have "junk" in subject keyword with powershell command.
    How shell i correct the following command;
    Powershell command:
     Get-Message -Filter {FromAddress -like "info@xxx.com"}  -SubjectKeywords "junk" -Deletecontent -confirm:$false 
    
    


    Salih Hanifeoglu Best Regards

    Monday, December 5, 2011 9:11 PM

Answers

  • Sorry I missed that the Export-mailbox cmdlet requires the -targetmailbox and targetfolder parameters. This means it takes a copy of the deleted items and places them into the target mailbox, etc. You can create a tmp mailbox for this and then drop it after you have confirmed you deleted the right content.

    Get-Mailbox -Identity INFOUSERNAME | Export-Mailbox -TargetMailbox TmpMailbox -TargetFolder Junk -SubjectKeywords “junk” -DeleteContent -Confirm:$false


    Sean Massey | Consultant, iUNITE

    Feel free to contact me through My Blog or Twitter.
    Please click the Mark as Answer button if a post solves your problem!

    • Marked as answer by emma.yoyo Monday, December 12, 2011 2:39 AM
    Tuesday, December 6, 2011 12:13 AM
  • Hi

    I think you can try -ContentKeywords "junk" instead of -SubjectKeywords "junk", because it select the Keyword in the subject which contents "junk", such as "juck mail","Mail junk"

    The command should be :

    Get-Mailbox -Identity info | Export-Mailbox -ContentKey words "junk" -TargetMailbox info@xxx.com -TargetFolder "Junk" -DeleteContent

    Dont forget create a new folder in OWA or outlook called "Juck", Sean's suggestion is quite correct. After running the command, you can delete them from the folder you created.

    Cheers

    Zi Feng

    • Marked as answer by emma.yoyo Monday, December 12, 2011 2:39 AM
    Tuesday, December 6, 2011 5:31 AM
    Moderator

All replies

  • Hi,

    So can you confirm that info@xxx.com is a mailbox inside your Exchange org? If this is correct then get the username for the info mailbox and try this: -

    Get-Mailbox -Identity INFOUSERNAME | Add-MailboxPermission -User YOURUSERNAME -AccessRights Fullaccess -InheritanceType all
    Get-Mailbox -Identity INFOUSERNAME | Export-Mailbox -SubjectKeywords “junk” -DeleteContent -Confirm:$false

    As always test code provided somewhere safe first.

     


    Sean Massey | Consultant, iUNITE

    Feel free to contact me through My Blog or Twitter.
    Please click the Mark as Answer button if a post solves your problem!

    Monday, December 5, 2011 10:49 PM
  • hi thank you  Mr.Sean;

     

    run to code return this error

    Error occurred in the step: Moving messages. Failed to copy messages to the

    destination mailbox store with error: 

    full error code:

     

    [PS] C:\Windows\system32>Get-Mailbox -Identity info | Export-Mailbox -SubjectKey

    words "junk" -DeleteContent -Confirm:$false

    Export-Mailbox : Error was found for Info (info@xxx.com) because:

    Error occurred in the step: Moving messages. Failed to copy messages to the destin

    ation mailbox store with error:

    MAPI or an unspecified service provider.

    ID no: 00000000-0000-00000000, error code: -1056749164

    At line:1 char:44

    + Get-Mailbox -Identity info | Export-Mailbox <<<<  -SubjectKeywords "junk" -De

    leteContent -Confirm:$false

        + CategoryInfo          : InvalidOperation: (0:Int32) [Export-Mailbox], Re

       cipientTaskException

        + FullyQualifiedErrorId : B1AE6DBB,Microsoft.Exchange.Management.Recipient

       Tasks.ExportMailbox

     

     

     


    Salih Hanifeoglu Best Regards
    Monday, December 5, 2011 11:15 PM
  • Sorry I missed that the Export-mailbox cmdlet requires the -targetmailbox and targetfolder parameters. This means it takes a copy of the deleted items and places them into the target mailbox, etc. You can create a tmp mailbox for this and then drop it after you have confirmed you deleted the right content.

    Get-Mailbox -Identity INFOUSERNAME | Export-Mailbox -TargetMailbox TmpMailbox -TargetFolder Junk -SubjectKeywords “junk” -DeleteContent -Confirm:$false


    Sean Massey | Consultant, iUNITE

    Feel free to contact me through My Blog or Twitter.
    Please click the Mark as Answer button if a post solves your problem!

    • Marked as answer by emma.yoyo Monday, December 12, 2011 2:39 AM
    Tuesday, December 6, 2011 12:13 AM
  • Hi

    I think you can try -ContentKeywords "junk" instead of -SubjectKeywords "junk", because it select the Keyword in the subject which contents "junk", such as "juck mail","Mail junk"

    The command should be :

    Get-Mailbox -Identity info | Export-Mailbox -ContentKey words "junk" -TargetMailbox info@xxx.com -TargetFolder "Junk" -DeleteContent

    Dont forget create a new folder in OWA or outlook called "Juck", Sean's suggestion is quite correct. After running the command, you can delete them from the folder you created.

    Cheers

    Zi Feng

    • Marked as answer by emma.yoyo Monday, December 12, 2011 2:39 AM
    Tuesday, December 6, 2011 5:31 AM
    Moderator
  • i tried but 

     

     

    [PS] C:\Windows\system32>Get-Mailbox -Identity info| Export-Mailbox -TargetMailb

    ox salih -TargetFolder Junk -SubjectKeywords "Teslim Edilmedi:" -DeleteContent -

    Confirm:$false

    Export-Mailbox : Error was found for Info (info@xxx.com) because: Err

    or occurred in the step: Creating target folder in the target mailbox. An unkno

    wn error has occurred., error code: -2147221233

    At line:1 char:43

    + Get-Mailbox -Identity info| Export-Mailbox <<<<  -TargetMailbox salih -Target

    Folder Junk -SubjectKeywords "Teslim Edilmedi:" -DeleteContent -Confirm:$false

        + CategoryInfo          : InvalidOperation: (0:Int32) [Export-Mailbox], Re

       cipientTaskException

        + FullyQualifiedErrorId : C68B49E2,Microsoft.Exchange.Management.Recipient

       Tasks.ExportMailbox

     


    Salih Hanifeoglu Best Regards
    Tuesday, December 6, 2011 12:49 PM
  • Hi

    Have you created a folder in TargetMailbox

    Also try to  quote -TargetFolder "Junk" in the command

    And about the error on Export-Mailbox command,   error code: -2147221233, just run FixMapi.exe from the command prompt easily fixes the problem.

    http://social.technet.microsoft.com/Forums/en/exchangesvradmin/thread/d27a7a79-7752-44f3-b9eb-314c5af10649

    Please try~~

    Cheers

    Zi Feng 



    Wednesday, December 7, 2011 3:50 AM
    Moderator
  • Hi

    Any update?

    Monday, December 12, 2011 1:29 AM
    Moderator
  • hi,  Zi Feng

    not run command  mauel delete  

    my solition,  otlutlook rule delete step by step

    plase write command

     


    Salih Hanifeoglu Best Regards
    Saturday, January 21, 2012 11:01 AM