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!
Who is Participating?
broeckskeConnect With a Mentor Commented:
No on second thought I will be more something like this:

Get-Mailbox | ForEach { remove-InboxRule -Name "NameOfTheRule" -Mailbox $_.Name}
have you tried:

Get-Mailbox | Remove-InboxRule -Identity "NameOfTheRule"
Razi_AhmedConnect With a Mentor Commented:
try this one

Get-Mailbox | forEach {Remove-Inboxrule –Identity “<Inbox Rule name>”}
BlazersITAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.