I was tasked with deleting a service account users old mail. Our CRM Mailbox user had 29.5GB of old mail floating around that needed to be purged. Adding access to the account was a no-no (and would probably crash out Outlook for a while) due to company policies. Powershell to the rescue?
I should probably mention that this is on Exchange 2010 in a DAG (2 servers) with SP3 hotfix 4 applied. Yes, I also know hotfix 5 is available.
I attempted to run the following script:
Search-Mailbox -Identity SOMEUSERNAME -SearchQuery '(Received:01/01/2012..12/31/2012)' -Deletecontent -Force
And I was told that the “search-mailbox” command was not found. Great. Verified that I was using the Exchange Management Powershell instead of just Windows PS. True story.
After a lot of searching I realized that our former Exchange Admin wasn’t very good at PowerShell. The Admin Tasks Management Powershell add-in was not available.
Check Available PowerShell Snap-ins
Get-PSSnapin
Notice Exchange Server Admin Tasks is not available.
Verify that the plugin is available
Get-PSSnapin -registered
Add the snap-in
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
I ended up closing the powershell window and then re-opening it. My search mailbox and delete content commands now work!
Other commands I did:
Added my user to the Discovery Management role in the ECP (https://yourmailserver.tld/ecp)
Created two new groups to allow the import and export of mailboxes, and then the exchange support and diagnostics:
New-RoleGroup -Name "Exchange Mailbox Import Export" -Roles "Mailbox Import Export" -Members "domain\username" -DisplayName "Exchange Mailbox Import Export" -Description "This group handles permissions to the import and export commands in powershell."
New-RoleGroup -Name "Exchange Support and Diagnostics" -Roles "Support Diagnostics" -Members "domain\username" -DisplayName "Exchange Support Diagnostics" -Description "This group handles permissions to the support diagnostics cmdlets in exchange."
“After a lot of searching I realized that our former Exchange Admin wasn’t very good at PowerShell.”
LOL
Does this work for Exchange online as well?