26 January 2018

Delete local Outlook Inbox Rules

In my existing local Outlook setup, my Inbox rules had grown up to an inmanagable amount. So I decided to clean the slate. However, I had no desire to press the Delete button over and over again.

Using PowerShell I was able to actually delete these local InboxRules with the script below.

Warning: this is a destructive script! Use at your own risk.

To use: just replace the  "YOUR INBOX NAME HERE" with your own inbox name and execute in a PowerShell shell of choice.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#################################################################################
# Title: delete outlook rules
# Description: deletes all outlook rules for a specific user
# 2018-01-26
################################################################################# 
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application

$namespace = $Outlook.GetNameSpace("MAPI")
$folder = $namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
$inbox = $namespace.Folders.Item("YOUR INBOX NAME HERE").Folders.Item("Inbox")
$store = $inbox.Store
$rules = $store.GetRules()
$rulescount = $rules.Count
"Number of rules found: $rulescount"

$index = 0
do
{
    $rules.Remove(1)
    $index++
}while ($index -le $rulescount)
$rules.Save()

$rulesleft = $inbox.Store.GetRules().count
"Number of rules left: $rulesleft"

Remove-Variable Outlook
Code formatted with: http://hilite.me/

I'm by no means a PowerShell expert. There might be better ways to do this. This little script gave me some pleasure assembling however and hopefully it helps someone else too.