I had to help a client with some PowerShell on an Exchange 2013 server the other day.
For reference here are the commands we ended up using. Note that these will only work with Exchange 2010 and newer. Microsoft started adding PowerShell commands to Exchange 2007 but it was only with 2010 that they came to full flower. To access these commands you will need to be on an Exchange box and open the special Exchange version of PowerShell.
Get-Mailbox -ResultSize unlimited | Get-InboxRule -ErrorAction SilentlyContinue | export-csv -notypeinformation rules.csv
get-mailbox -organizationalunit users | get-mailboxrule -ErrorAction SilentlyContinue | export-csv -notypeinformation rules.csv
We added the -ErrorAction SilentlyContinue to get-inboxrule because it threw an error every time it encountered a mailbox without a rule.
get-mailbox | Search-Mailbox -SearchQuery 'Subject:"Your bank statement"' -DeleteContent
You will want to run this first without the -DeleteContent to make sure you got it right :)
You might have to add yourself as a member of the group "Discovery Management" for the search-mailbox commandlet to be visible.
Additional Permissions are needed for Parameter -DeleteContent
To be able to use the -DeleteContent Parameter you need to have "Mailbox Import Export" permissions. Without these permissions, the parameter -DeleteContent is not available for the Search-Mailbox Command.
- Create a new Security Group
- Enter the following command in Exchange Management Shell (replace the Security Group name accordingly):
New-ManagementRoleAssignment -Name "Import Export Support" -SecurityGroup ImportExport -Role "Mailbox Import Export"