Answered by:
Removing specific messages from your with Powershell command:

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
- Edited by Salih Hanifeoglu Monday, December 5, 2011 10:07 PM
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 AMModerator
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:$falseAs 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 RegardsMonday, 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 AMModerator -
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 RegardsTuesday, 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.
Please try~~
Cheers
Zi Feng
- Edited by Zi FengModerator Thursday, December 8, 2011 6:20 AM
Wednesday, December 7, 2011 3:50 AMModerator -
Hi
Any update?
Monday, December 12, 2011 1:29 AMModerator -
hi, Zi Feng
not run command mauel delete
my solition, otlutlook rule delete step by step
plase write command
Salih Hanifeoglu Best RegardsSaturday, January 21, 2012 11:01 AM