blackmores
asked on
Need to delete email from all users mailboxes
I have an email that has been sent to everyone in the company. I want to delete this email from everyone's computer to minimise damage. A log of who it deleted from, and copies of the emails in a dedicated mailbox would be great too.
Our environment is Exchange 2010 SP1, so that means Exhcange 2007 or Exchange 2010 process for doing this is different.
I have tried running the following commands but had little success.
- I have been running the command from the enterprise admin credentials.
- The first command returned this result:
-The second command returned a similar response.
-When i run the command without the deletecontent switch, but include targetmailbox i can see it finds a number of these emails.
Any help would be appreicated.
Ivan
Our environment is Exchange 2010 SP1, so that means Exhcange 2007 or Exchange 2010 process for doing this is different.
I have tried running the following commands but had little success.
Get-Mailbox -Server "*SERVER*" | Search-Mailbox -TargetMailbox "*SEARCHACCOUNT*" -TargetFolder "*EMAILSDELETED*" -SearchQuery 'Subject:"*SUBJECT CONTAINS THIS*" AND Body:"*BODY CONTAINS THIS*"' -deletecontent
Get-Mailbox -Server “*SERVER*” | Search-Mailbox -SearchQuery ‘Subject:”*SUBJECT CONTAINS THIS*” Body:"*BODY CONTAINS THIS*"‘ -DeleteContent
- I have been running the command from the enterprise admin credentials.
- The first command returned this result:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (*MAILBOXNAME*:PSObject) [Search-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Search-Mailbox
-The second command returned a similar response.
-When i run the command without the deletecontent switch, but include targetmailbox i can see it finds a number of these emails.
Any help would be appreicated.
Ivan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great advice and nice article from Antoine that should serve you well
ASKER
Hi Akhater,
I rant through the steps you suggested. Below is the command and the output i recieved when i ran the permissions step:
Then i ran the following command as per your suggestion:
For both, this was the output i received:
Cheers,
Ivan
P.S. Your article was a good read, and very straight forward. Will be noting that one down.
I rant through the steps you suggested. Below is the command and the output i recieved when i ran the permissions step:
[PS] C:\Windows\system32>New-ManagementRo leAssignme nt -Name "Import Export Mailbox Admins" -SecurityGroup "Exchange Mail
box Support" -Role "Mailbox Import Export"
Name Role RoleAssigneeName RoleAssigneeType AssignmentMethod EffectiveUserNam
e
---- ---- ---------------- ---------------- ---------------- ----------------
Import Export Mailbox Admins Mailbox Import... Exchange Mailb... SecurityGroup Direct
Then i ran the following command as per your suggestion:
[PS] C:\Windows\system32>$mbxes = Get-Mailbox -Server "*SERVER*" -resultsize unlimited
[PS] C:\Windows\system32>$mbxes | Search-Mailbox -SearchQuery 'Subject:"*SUBJECT CONTAINS THIS*" Body:"*BODY CONTAINS THIS*"
' -DeleteContent
I also tried:[PS] C:\Windows\system32>Get-Mailbox -Server "*SERVER*" -resultsize unlimited | Search-Mailbox -SearchQuery 'Subject:"*SUBJECT CONTAINS THIS*" Body:"*BODY CONTAINS THIS*"' -DeleteContent
For both, this was the output i received:
The target mailbox or .pst file path is required.
+ CategoryInfo : InvalidArgument: (:) [], ArgumentException
+ FullyQualifiedErrorId : 78CD297B
Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\administrator.BLACKMORES\Ap pData\Roam ing\Micros oft\Exchan ge\RemoteP owerShell\ *SERVER.DO MAIN*\*SER VER*.domai n.psm1:429 91 char:29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
+ FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShel l.Commands .InvokeCom mandComman d
Cheers,
Ivan
P.S. Your article was a good read, and very straight forward. Will be noting that one down.
it seems you have an issue with the 'Subject:"*SUBJECT CONTAINS THIS*" Body:"*BODY CONTAINS THIS*"' part
try to replace it by '"Subject:*SUBJECT CONTAINS THIS*" and "Body:*BODY CONTAINS THIS*"'
just make sure it is a ' followed by a " in the start and " followed by a ' at the end
try to replace it by '"Subject:*SUBJECT CONTAINS THIS*" and "Body:*BODY CONTAINS THIS*"'
just make sure it is a ' followed by a " in the start and " followed by a ' at the end
ASKER
Hi All,
Here are two commands i tried, and the two returns i recieved:
And
Note the difference between the two is the inverted commas. I also typed the keys directly into the console so its not incorrect markup from a text editor
Any help appreciated.
ivan
Here are two commands i tried, and the two returns i recieved:
[PS] C:\Windows\system32>Get-Mailbox -Server "EXCHANGE" -resultsize unlimited | Search-Mailbox -SearchQuery 'Subject:"RE: Mobile Phones" Body:"0400 000000"' -DeleteContent
The target mailbox or .pst file path is required.
+ CategoryInfo : InvalidArgument: (:) [], ArgumentException
+ FullyQualifiedErrorId : 78CD297B
Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\administrator.BLACKMORES\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\*SERVER.DOMAIN*\*SERVER*.domain.psm1:42991 char:29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
+ FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand
And
[PS] C:\Windows\system32>Get-Mailbox -Server "EXCHANGE" -resultsize unlimited | Search-Mailbox -SearchQuery '"Subject:RE: Mobile Phones" "Body:0400 000000"' -DeleteContent
The target mailbox or .pst file path is required.
+ CategoryInfo : InvalidArgument: (:) [], ArgumentException
+ FullyQualifiedErrorId : 78CD297B
Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\administrator.BLACKMORES\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\*SERVER.DOMAIN*\*SERVER*.domain.psm1:42991 char:29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
+ FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand
Note the difference between the two is the inverted commas. I also typed the keys directly into the console so its not incorrect markup from a text editor
Any help appreciated.
ivan
ASKER
Performing further tests, i tired the following command based on infomation o got here and get a different error:
Hope that helps,
Ivan
[PS]Get-Mailbox -Server "EXCHANGE" -resultsize unlimited | Search-Mailbox -targetmailbox "mymailbox" -targetfolder "deletecommand" -SearchQuery 'Subject:"RE: Mobile Phones" Body:"0400 000000"' -DeleteContent
The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (CS Temp2:PSObject) [Search-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Search-Mailbox
Hope that helps,
Ivan
please try this
Get-Mailbox -Server "EXCHANGE" -resultsize unlimited | Search-Mailbox -SearchQuery '"Subject:RE: Mobile Phones" and "Body:0400 000000"' -DeleteContent
Get-Mailbox -Server "EXCHANGE" -resultsize unlimited | Search-Mailbox -SearchQuery '"Subject:RE: Mobile Phones" and "Body:0400 000000"' -DeleteContent
ASKER
The result as expected was:
I have tried to simplify things, so i tried the following command:
I tried the -DeleteContent switch and that too worked as expected.
The problem is that the initial Get-Mailbox -Server "EXCHANGE" -resultsize unlimited does not appear to be passing through the user names down the pipe (as the error suggests).
If i run
Regards,
Ivan
The input object cannot be bound to any parameters for the command either because the command does not take pipeline in
put or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (USER:PSObject) [Search-Mailbox], ParameterBindingException
I have tried to simplify things, so i tried the following command:
[PS] Search-Mailbox -identity "ivan" -targetmailbox "admin" -targetfolder "deletecommand" -Searc
hQuery "Subject:'Ivan Test Delete Email Through Exchange'" -LogOnly -LogLevel Full
The above worked successfully!I tried the -DeleteContent switch and that too worked as expected.
The problem is that the initial Get-Mailbox -Server "EXCHANGE" -resultsize unlimited does not appear to be passing through the user names down the pipe (as the error suggests).
If i run
Search-Mailbox -SearchQuery '"Subject:RE: Mobile Phones" and "Body:0400 000000"' -DeleteContent
or similar, it prompts to input an identity.Regards,
Ivan
ASKER
Correction, the -LogOnly -LogLevel Full works successfully
the -DeleteContent comes up with the following error:
the -DeleteContent comes up with the following error:
A positional parameter cannot be found that accepts argument '-deletecontent'.
+ CategoryInfo : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox
Type search-mailbox -delte(press tab) does it autocomplete ?
If not then you have a permission issue did you follow steps in my article?
If not then you have a permission issue did you follow steps in my article?
ASKER
@Akhater, i have checked the recommendation and it did NOT resolve.
i assumed that it was a type (search-mailbox -delte) and instead i tried (search-mailbox -delet) and after pressing TAB it resolved.
Attached is the screenshot of the command:
Get-ManagementRoleAssignme nt -Role "mailbox import export"
The user that im running the command with is part of that group.
Regards,
Ivan
exchange1.jpg
i assumed that it was a type (search-mailbox -delte) and instead i tried (search-mailbox -delet) and after pressing TAB it resolved.
Attached is the screenshot of the command:
Get-ManagementRoleAssignme
The user that im running the command with is part of that group.
Regards,
Ivan
exchange1.jpg
ASKER
I just entered the following command and it worked successfully:
Search-Mailbox -identity "ivand" -SearchQuery "Subject:'Ivan Test Delete Email Through Exchange'" -deletecontent
I think the problem is when i what to apply it to multiple mailboxes.
Ivan
Search-Mailbox -identity "ivand" -SearchQuery "Subject:'Ivan Test Delete Email Through Exchange'" -deletecontent
I think the problem is when i what to apply it to multiple mailboxes.
Ivan
since you have now the -DeleteContent then you assigned the permission correctly
for multiple mailboxes please follow my first post
$mbxes = Get-Mailbox -Server “*SERVER*” -resultsize unlimited
$mbxes | Search-Mailbox -SearchQuery ‘Subject:”*SUBJECT CONTAINS THIS*” Body:"*BODY CONTAINS THIS*"‘ -DeleteContent
thanks
for multiple mailboxes please follow my first post
$mbxes = Get-Mailbox -Server “*SERVER*” -resultsize unlimited
$mbxes | Search-Mailbox -SearchQuery ‘Subject:”*SUBJECT CONTAINS THIS*” Body:"*BODY CONTAINS THIS*"‘ -DeleteContent
thanks
ASKER
@Akhater,
The problem is resolved. I beleive the resolution was your permissions issue, however it must have taken some time to propegate as it did not work imediately.
Thanks for your help.
The problem is resolved. I beleive the resolution was your permissions issue, however it must have taken some time to propegate as it did not work imediately.
Thanks for your help.
ASKER
Nice blog.
tx for the update and for the points