Removing specific messages from your with Powershell command:
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
December 6th, 2011 12:11am
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!
Free Windows Admin Tool Kit Click here and download it now
December 6th, 2011 1:49am
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
December 6th, 2011 2:15am
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:$falseSean 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!
Free Windows Admin Tool Kit Click here and download it now
December 6th, 2011 3:13am
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:$falseSean 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!
December 6th, 2011 3:13am
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
Free Windows Admin Tool Kit Click here and download it now
December 6th, 2011 7:56am
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
December 6th, 2011 8:31am
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
Free Windows Admin Tool Kit Click here and download it now
December 6th, 2011 8:31am
Have you created a folder in TargetMailbox
Also try to quote -TargetFolder "Junk" in the command
December 6th, 2011 10:58pm
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
Free Windows Admin Tool Kit Click here and download it now
December 7th, 2011 6:50am
Hi
Any update?
December 11th, 2011 8:31pm
hi, Zi Feng
not run command mauel delete
my solition, otlutlook rule delete step by step
plase write command
Salih Hanifeoglu Best Regards
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2012 6:03am