Add mail rule with keywords in exchnage online with command

To add a mail rule with keywords in Exchange Online using the Exchange Online PowerShell module, you can use the following command:

New-MailRule -Name <RuleName> -Conditions @{ContainsKeywords = @("keyword1", "keyword2",...)} -Actions @{MoveToFolder = "<FolderName>"}

Here:

For example, to create a rule that moves messages that contain the keywords "urgent" or "important" to a folder named "Urgent", you would use the following command:

New-MailRule -Name "Urgent Messages" -Conditions @{ContainsKeywords = @("urgent", "important")} -Actions @{MoveToFolder = "Urgent"}

You can also use other conditions and actions, such as:

You can also use the New-MailRule cmdlet with the -Query parameter to specify a more complex query using the Exchange Search syntax. For example:

New-MailRule -Name "Urgent Messages" -Query "subject:urgent OR subject:important" -Actions @{MoveToFolder = "Urgent"}

This will create a rule that applies to messages with subjects that contain the words "urgent" or "important", and moves them to the "Urgent" folder.

Note: You need to have the Exchange Online PowerShell module installed and configured on your system to use these commands. You can install the module by running the following command: Install-Module -Name ExchangeOnline