Multiple Actions for one Outlook rule in Powershell

﹥>﹥吖頭↗ 提交于 2019-12-06 12:04:35

Can I add multiple actions to the same outlook rule in powershell? if so, how?

Took a bit but I got a working test that uses multiple actions applied to a single rule. It is actually easy and you just need to repeat the steps you have already done and create a different action variable.

In my example, just showing the end of the code, I have added a action to display a message in the New Item Alert window.

...
$action = $rule.Actions.MoveToFolder
$action.Enabled = $true 

$anotherAction = $rule.Actions.NewItemAlert
$anotherAction.Text = "I am awesome!"
$anotherAction.Enabled = $true 

[Microsoft.Office.Interop.Outlook._MoveOrCopyRuleAction].InvokeMember("Folder",[System.Reflection.BindingFlags]::SetProperty,$null, $action, $deleted)

$rules.Save()

You quite possibly already tried something like this. If not there is an important reference for this that you need to be aware of.

What is the syntax / code for the "run script" action?

This is one of the actions you cannot programatically set as per this reference for Office 2007 or this one for Office 2010/2013. The tables are similar and rather large to include here but I will reference the one in your 2nd bullet.

Action                                              : Start a script
Constant in olRuleActionType                        : olRuleActionRunScript
Supported when creating new rules programmatically? : No
Apply to olRuleReceive rules?                       : Yes
Apply to olRuleSend rules?                          : No

There are others as well where you are restricted. So you need to keep that in mind when you are making your rules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!