Link to home
Start Free TrialLog in
Avatar of BlazersIT
BlazersIT

asked on

Globally remove an inbox rule with Powershell

Is there Powershell command to globally remove an inbox rule for all users in a database in Exchange 2010?  We have over 400 users and I'd prefer to automate this instead of running "remove-inboxrule -mailbox xxx..." command all day long!  Thanks!
Avatar of broeckske
broeckske

have you tried:

Get-Mailbox | Remove-InboxRule -Identity "NameOfTheRule"
ASKER CERTIFIED SOLUTION
Avatar of broeckske
broeckske

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlazersIT

ASKER

Thanks.  using -Identity instead of -Name in broeckske's suggestion worked so I am giving Razi credit also.
None of these solutions will work if a mailbox contains rules with  duplicated names. If, for instance, a mailbox has 5 copies of a filter called [SPAM], the solutions above will throw errors and won't remove anything.

To delete duplicates you need to iterate through all of the filters on each mailbox and delete them one by one. The below snippet will generate the powershell commands needed to do this for each mailbox. From  a batch I redirect this output to a file, grep just the Get-InboxRule lines and output it to a temporary .ps1 file which the batch then proceeds to call so it can all be one click and clean.

$users = get-mailbox -resultsize unlimited | foreach-Object {
$this_name =$_.Name
write-Host Get-InboxRule -Mailbox `"$this_name`" `| where `{`$_.Name `-eq `"[SPAM]`"`} `| Remove-InboxRule `-Confirm:`$False `-Force
write-Host
}

-Matt