- Get link
- X
- Other Apps
Step 1 - Add your admin id to “Discovery Management” group
You can’t use Search-Mailbox cmd unless you have “Discovery Management” Group Rights, you can use EAC to Manage Role Group and Grant permission to your account.
Step 2 - To use -DeleteContent switch your account requires "Mailbox Import Export" role Access you can follow the below steps for the same.
Step 3 - Run the below PowerShell to Remove the Messages
Below is the example of command I used where I had to delete email from the entire mailboxes in Organization from sender Example@gmail.com
To Query through all the mailboxes I created an array for all the mailboxes.
$mbx = Get-mailbox -resultsize Unlimited
Use below command to delete mail from all the mailboxes in organizations.
$mbx | Search-Mailbox -SearchQuery "from:Example@gmail.com" -TargetMailbox “AdminMailbox” -TargetFolder "DeleteReport" -DeleteContent –Force -LogLevel Full
Note: By default –loglevel value is set to Basic if you want full details or message delete use -log level full.
You can also use the subject for SearchQuery
$mbx | Search-Mailbox -SearchQuery "Subject:This is Test Msg" -TargetMailbox “AdminMailbox” -TargetFolder "DeleteReport" -DeleteContent –Force -LogLevel Full
You can’t use Search-Mailbox cmd unless you have “Discovery Management” Group Rights, you can use EAC to Manage Role Group and Grant permission to your account.
Step 2 - To use -DeleteContent switch your account requires "Mailbox Import Export" role Access you can follow the below steps for the same.
- Create a group Name Import and Export and add the admin account
- Add the admin ID to the role group.
Step 3 - Run the below PowerShell to Remove the Messages
Below is the example of command I used where I had to delete email from the entire mailboxes in Organization from sender Example@gmail.com
To Query through all the mailboxes I created an array for all the mailboxes.
$mbx = Get-mailbox -resultsize Unlimited
Use below command to delete mail from all the mailboxes in organizations.
$mbx | Search-Mailbox -SearchQuery "from:Example@gmail.com" -TargetMailbox “AdminMailbox” -TargetFolder "DeleteReport" -DeleteContent –Force -LogLevel Full
Note: By default –loglevel value is set to Basic if you want full details or message delete use -log level full.
You can also use the subject for SearchQuery
$mbx | Search-Mailbox -SearchQuery "Subject:This is Test Msg" -TargetMailbox “AdminMailbox” -TargetFolder "DeleteReport" -DeleteContent –Force -LogLevel Full
- Get link
- X
- Other Apps
Comments
Hello. I had to run this command for our on prem Exchange today and it cleaned a rouge message to over 1000 users. However when I run this command in O365 with your instructions, I get an error that Search-Mailbox is not recognized. I have loaded the Exchange cmdlets in 0365 as I can do a Get-Mailbox and it returns the list of users. Any ideas.
ReplyDeleteThank you.
Ken M
Hi. Disregard my previous comment. After I re read the post and saw your instructions at the beginning to add my Global admin to the Discovery Role Group, and create the import export group and assign my admin to that role, the command ran. Thank you for the helpful post.
ReplyDeleteKenM