Skip to content

Commit 13b2fba

Browse files
committed
Automatic commit Fri May 20 04:16:43 PM EEST 2022
1 parent 6dabb2d commit 13b2fba

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#Requires -version 2.0
2+
#Author: Alamot
3+
Add-Type -AssemblyName microsoft.office.interop.outlook
4+
$outlook = New-Object -ComObject outlook.application
5+
$namespace = $Outlook.GetNameSpace("mapi")
6+
7+
8+
# See https://docs.microsoft.com/en-us/office/vba/api/outlook.olruleactiontype
9+
$ACTIONS_TO_GRAB = @(6, 7, 8)
10+
# 6 => olRuleActionForward
11+
# 7 => olRuleActionForwardAsAttachment
12+
# 8 => olRuleActionRedirect
13+
14+
15+
[Hashtable[]]$records = $null
16+
17+
ForEach ($store in $namespace.Stores) {
18+
19+
$records += @{}
20+
$records[-1]['CurrentUser'] = $namespace.CurrentUser.Name
21+
$records[-1]['DisplayName'] = $store.DisplayName
22+
$records[-1]['FilePath'] = $store.FilePath
23+
$records[-1]['Rules'] = $()
24+
25+
$rules = $store.GetRules()
26+
27+
ForEach ($rule in $rules) {
28+
29+
if ($rule.Enabled) {
30+
31+
$records[-1]['Rules'] += , @{}
32+
$records[-1]['Rules'][-1]['name'] = $rule.Name
33+
$records[-1]['Rules'][-1]['conditions'] = @()
34+
$records[-1]['Rules'][-1]['actions'] = @()
35+
36+
ForEach ($condition in $rule.Conditions) {
37+
if ($condition.Enabled) {
38+
# https://docs.microsoft.com/en-us/office/vba/api/outlook.olruleconditiontype
39+
$s = "type:" + $condition.ConditionType.toString()
40+
if ("Text" -in $condition.PSobject.Properties.Name) {
41+
$s += ", text:" + $condition.Text;
42+
}
43+
if ("Recipients" -in $condition.PSobject.Properties.Name) {
44+
$s += ", recipients:" +
45+
(($condition.Recipients | select -expand Name) -join ';')
46+
}
47+
$records[-1]['Rules'][-1]['conditions'] += , $s
48+
}
49+
}
50+
51+
ForEach ($action in $rule.Actions) {
52+
if ($action.Enabled -and ($ACTIONS_TO_GRAB -contains $action.ActionType)) {
53+
$s = "type:" + $action.ActionType.toString() + ", recipients:" +
54+
(($action.Recipients | select -expand Name) -join ';')
55+
$records[-1]['Rules'][-1]["actions"] += , $s
56+
}
57+
}
58+
59+
}
60+
}
61+
}
62+
63+
$records | ConvertTo-Json -Depth 10

0 commit comments

Comments
 (0)