Dear Community,
I am currently trying to generate an outlook rule for incoming mail automatically by filling some of the rules fields with data coming from some previous Power Automate variables (Number & Outlook Folder).
The rule is supposed to look for a specific number (variable) in any incoming mail subject and move it in a specific folder.
I reached some results using the recorder but it seems that this solution is not really robust so I tried to go on some Powershell scripting.
In a first step I skipped the variable aspect to focus on the script itself and unfortunately I have some troubles.
$Outlook = New-Object -ComObject Outlook.Application
$Namespace = $Outlook.GetNameSpace("MAPI")
$Inbox = $Namespace.GetDefaultFolder(6)
$SubFolder = $Inbox.Folders.Item("#Segment")
#Setting the name of the rule
$Rules = $Namespace.DefaultStore.GetRules()
$Rule = $Outlook.Session.DefaultStore.GetRules().Create("Rule Name", [Microsoft.Office.Interop.Outlook.OlRuleType]::olRuleReceive)
#Setting the condition: looking for the word "dedicated" in the subject of the mail
$Condition = $Rule.Conditions.Subject
$Condition.Enabled = $true
$Condition.Text = @("Dedicated")
#Action of the rule
$Action = $Rule.Actions.MoveToFolder
$Action.Enabled = $true
$Action.Folder = $Subfolder
#Enabling of the rule and saving showing a progress popup
$Rule.Enabled = $true
$Rules.Save($true)
This error is generated and despite some hours of research I could not find the solution to fix it.
One or more rules cannot be saved because of invalid actions or conditions.
At line:1 char:1
+ $Rule.Enabled = $true
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Any suggestion would be helpfull.
Many thanks in advance.