Initial Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

LLM Generation

Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

Output

Here's a PowerShell script that creates and enables email inbox rules to automatically move emails with specific keywords to the trash using Exchange Online PowerShell:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Script to create inbox rules for filtering unwanted emails based on subject keywords

# Function to connect to Exchange Online
function Connect-ExchangeOnline {
    try {
        # Import Exchange Online Module
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        
        # Connect to Exchange Online
        Write-Host "Connecting to Exchange Online..." -ForegroundColor Yellow
        Connect-ExchangeOnline
        Write-Host "Successfully connected to Exchange Online." -ForegroundColor Green
    }
    catch {
        Write-Host "Error connecting to Exchange Online: $($_.Exception.Message)" -ForegroundColor Red
        exit
    }
}

# Function to create inbox rule
function New-KeywordRule {
    param (
        [string]$Mailbox,
        [string]$RuleName,
        [string[]]$Keywords
    )
    
    try {
        # Create the rule
        New-InboxRule -Mailbox $Mailbox `
                     -Name $RuleName `
                     -SubjectContainsWords $Keywords `
                     -MoveToFolder "Deleted Items" `
                     -Enabled $true

        Write-Host "Successfully created rule '$RuleName' for mailbox $Mailbox" -ForegroundColor Green
    }
    catch {
        Write-Host "Error creating rule: $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Main script
try {
    # Connect to Exchange Online
    Connect-ExchangeOnline

    # Get user's email address
    $userEmail = Read-Host "Enter the email address for which to create rules"

    # Define keywords list (can be modified as needed)
    $spamKeywords = @(
        "lottery",
        "winner",
        "inheritance",
        "millionaire",
        "bitcoin",
        "cryptocurrency",
        "urgent",
        "Nigerian prince",
        "bank transfer",
        "free money"
    )

    # Create rule name
    $ruleName = "Spam Subject Filter"

    # Create the inbox rule
    New-KeywordRule -Mailbox $userEmail -RuleName $ruleName -Keywords $spamKeywords

    # Verify rule creation
    $rule = Get-InboxRule -Mailbox $userEmail -Identity $ruleName
    if ($rule) {
        Write-Host "`nRule details:" -ForegroundColor Cyan
        Write-Host "Name: $($rule.Name)"
        Write-Host "Enabled: $($rule.Enabled)"
        Write-Host "Keywords: $($rule.SubjectContainsWords -join ', ')"
    }

}
catch {
    Write-Host "An error occurred: $($_.Exception.Message)" -ForegroundColor Red
}
finally {
    # Disconnect from Exchange Online
    Disconnect-ExchangeOnline -Confirm:$false
    Write-Host "`nDisconnected from Exchange Online." -ForegroundColor Yellow
}
This script: 1. Defines a function to connect to Exchange Online 2. Creates a function to set up inbox rules 3. Allows you to specify an email address 4. Creates a rule that moves emails containing specified keywords in the subject to the Deleted Items folder 5. Verifies the rule creation 6. Includes error handling and cleanup To use this script: 1. Make sure you have the Exchange Online PowerShell module installed:
1
Install-Module -Name ExchangeOnlineManagement
2. You need to have appropriate administrative permissions in your Exchange Online environment. 3. Save the script with a .ps1 extension and run it in PowerShell. To customize the keywords: - Modify the `$spamKeywords` array in the script to include your desired keywords. Additional notes: 1. The script requires: - PowerShell 5.1 or later - Exchange Online PowerShell module - Appropriate Exchange Online permissions 2. You can modify the script to: - Add more conditions (from address, body content, etc.) - Change the action (delete instead of move to trash) - Add exceptions - Create multiple rules 3. To modify existing rules, you can use: - `Set-InboxRule` - `Remove-InboxRule` - `Get-InboxRule` Safety considerations: - Test the rules with non-critical emails first - Regularly review the rules to ensure they're not filtering important emails - Consider adding exceptions for important senders Example usage:
1
.\Create-SpamRules.ps1
The script will prompt for the email address and create the rule with the specified keywords.

Check if all of the following conditions are true:

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string New-PSSession: False

Substring Evaluation

Testing if the previous output contains the string Connect-ExchangeOnline: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -MoveToFolder: True

Substring Evaluation

Testing if the previous output contains the string -DeleteMessage: False

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -SubjectOrBodyContainsWords: False

Substring Evaluation

Testing if the previous output contains the string -SubjectContainsWords: True

Final Answer: True

Substring Evaluation

Testing if the previous output contains the string New-InboxRule: True

Final Answer: True

Initial Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

LLM Generation

Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

Output

Here's a PowerShell script that creates email inbox rules to automatically move emails containing specific keywords to the trash using the Exchange Online PowerShell module:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Script to create inbox rules for filtering unwanted emails based on subject keywords

# Connect to Exchange Online
function Connect-ExchangeOnline {
    try {
        # Import Exchange Online Module
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        
        # Connect to Exchange Online
        Write-Host "Connecting to Exchange Online..." -ForegroundColor Yellow
        Connect-ExchangeOnline -ShowProgress $true
        
        Write-Host "Successfully connected to Exchange Online." -ForegroundColor Green
    }
    catch {
        Write-Host "Error connecting to Exchange Online: $_" -ForegroundColor Red
        exit
    }
}

# Function to create inbox rule
function New-KeywordInboxRule {
    param (
        [string]$Mailbox,
        [string]$RuleName,
        [string[]]$Keywords
    )
    
    try {
        # Create the rule
        New-InboxRule -Mailbox $Mailbox `
                     -Name $RuleName `
                     -SubjectContainsWords $Keywords `
                     -MoveToFolder "Deleted Items" `
                     -Enabled $true

        Write-Host "Successfully created rule '$RuleName' for mailbox '$Mailbox'" -ForegroundColor Green
    }
    catch {
        Write-Host "Error creating rule '$RuleName': $_" -ForegroundColor Red
    }
}

# Main script
function Main {
    # Connect to Exchange Online
    Connect-ExchangeOnline

    # Define the mailbox
    $mailbox = Read-Host "Enter the email address to create rules for"

    # Define keywords for filtering
    $spamKeywords = @(
        "urgent",
        "winner",
        "lottery",
        "prize",
        "million dollars",
        "inheritance",
        "bank transfer",
        "investment opportunity",
        "cryptocurrency",
        "work from home"
        # Add more keywords as needed
    )

    # Create rule name
    $ruleName = "Spam Filter - Automatic Deletion"

    # Create the inbox rule
    New-KeywordInboxRule -Mailbox $mailbox -RuleName $ruleName -Keywords $spamKeywords

    # Display existing rules
    Write-Host "`nCurrent inbox rules for $mailbox:" -ForegroundColor Yellow
    Get-InboxRule -Mailbox $mailbox | Format-Table Name, Enabled, Description

    # Disconnect from Exchange Online
    Disconnect-ExchangeOnline -Confirm:$false
    Write-Host "`nDisconnected from Exchange Online." -ForegroundColor Yellow
}

# Run the script
Main
This script does the following: 1. Defines a function to connect to Exchange Online using the ExchangeOnlineManagement module. 2. Creates a function to set up inbox rules that will move emails with specific keywords in their subjects to the Deleted Items folder. 3. The main function: - Connects to Exchange Online - Prompts for the target mailbox - Defines a list of spam keywords - Creates the inbox rule - Displays all current inbox rules - Disconnects from Exchange Online To use this script: 1. First, ensure you have the Exchange Online PowerShell module installed:
1
Install-Module -Name ExchangeOnlineManagement
2. Save the script with a .ps1 extension 3. Run the script with administrator privileges 4. When prompted, enter the email address for which you want to create the rules Important notes: - You need appropriate permissions to create inbox rules for the target mailbox - You must have the Exchange Online PowerShell module installed - The account you use must have the necessary Exchange Online administrative privileges - You can modify the $spamKeywords array to include any keywords you want to filter - The script creates one rule with multiple keywords, but you could modify it to create separate rules for different sets of keywords To modify the keywords, simply edit the $spamKeywords array in the script:
1
2
3
4
5
6
$spamKeywords = @(
    "your",
    "custom",
    "keywords",
    "here"
)
To delete a rule if needed:
1
Remove-InboxRule -Mailbox user@domain.com -Identity "Spam Filter - Automatic Deletion"
Remember that this script will move matching emails directly to the Deleted Items folder, so use it carefully and review the filtered emails periodically to ensure legitimate emails aren't being filtered accidentally.

Check if all of the following conditions are true:

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string New-PSSession: False

Substring Evaluation

Testing if the previous output contains the string Connect-ExchangeOnline: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -MoveToFolder: True

Substring Evaluation

Testing if the previous output contains the string -DeleteMessage: False

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -SubjectOrBodyContainsWords: False

Substring Evaluation

Testing if the previous output contains the string -SubjectContainsWords: True

Final Answer: True

Substring Evaluation

Testing if the previous output contains the string New-InboxRule: True

Final Answer: True

Initial Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

LLM Generation

Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

Output

Here's a PowerShell script that creates and enables email inbox rules to automatically route emails containing specific keywords to the trash using Exchange Online PowerShell:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Connect to Exchange Online
Connect-ExchangeOnline

# Function to create inbox rule
function Create-InboxRule {
    param (
        [string]$RuleName,
        [string[]]$Keywords,
        [string]$Mailbox
    )

    try {
        # Check if rule already exists
        $existingRule = Get-InboxRule -Mailbox $Mailbox | Where-Object {$_.Name -eq $RuleName}
        
        if ($existingRule) {
            Write-Host "Rule '$RuleName' already exists. Updating..." -ForegroundColor Yellow
            Remove-InboxRule -Identity $existingRule.Identity -Confirm:$false
        }

        # Create new rule
        New-InboxRule -Name $RuleName `
                     -Mailbox $Mailbox `
                     -SubjectContainsWords $Keywords `
                     -DeleteMessage $true `
                     -Enabled $true

        Write-Host "Rule '$RuleName' created successfully!" -ForegroundColor Green
    }
    catch {
        Write-Host "Error creating rule: $_" -ForegroundColor Red
    }
}

# Specify the email address for the mailbox
$mailboxAddress = Read-Host "Enter the email address for the mailbox"

# Define keywords that trigger the rule
$spamKeywords = @(
    "spam",
    "win",
    "lottery",
    "prize",
    "viagra",
    "cialis",
    "winner",
    "free money",
    "inheritance",
    "bank transfer",
    "Nigerian prince",
    "cryptocurrency investment",
    "get rich quick",
    "make money fast",
    "work from home opportunity"
)

# Create rule for spam keywords
Create-InboxRule -RuleName "Spam Filter Rule" -Keywords $spamKeywords -Mailbox $mailboxAddress

# Define promotional keywords
$promotionalKeywords = @(
    "discount",
    "sale",
    "special offer",
    "limited time",
    "clearance",
    "% off",
    "deal",
    "promotion",
    "subscribe",
    "newsletter",
    "exclusive offer"
)

# Create rule for promotional emails
Create-InboxRule -RuleName "Promotional Filter Rule" -Keywords $promotionalKeywords -Mailbox $mailboxAddress

# List all inbox rules for verification
Write-Host "`nCurrent Inbox Rules:" -ForegroundColor Cyan
Get-InboxRule -Mailbox $mailboxAddress | Format-Table Name, Enabled, Description

# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false

Write-Host "`nScript completed successfully!" -ForegroundColor Green
This script: 1. Connects to Exchange Online (requires Exchange Online PowerShell module) 2. Defines a function `Create-InboxRule` that: - Checks if a rule with the same name exists - Removes the existing rule if found - Creates a new rule with specified keywords - Enables the rule automatically 3. Prompts for the target mailbox email address 4. Defines two sets of keywords: - Spam-related keywords - Promotional email keywords 5. Creates two separate rules: - One for spam-related emails - One for promotional emails 6. Lists all current inbox rules for verification 7. Disconnects from Exchange Online To use this script: 1. First, install the Exchange Online PowerShell module if you haven't already:
1
Install-Module -Name ExchangeOnlineManagement
2. Save the script with a .ps1 extension 3. Run the script in PowerShell:
1
.\YourScriptName.ps1
4. Enter your email address when prompted Notes: - You need appropriate permissions to create inbox rules for the specified mailbox - You'll need to authenticate with Exchange Online when connecting - You can modify the keywords arrays to add or remove terms as needed - The script creates rules that move matching emails directly to the trash - You can modify the script to create different actions (like moving to a folder instead of deleting) - The rules are created with the "OR" condition, meaning if any of the keywords match, the rule will trigger To customize the script: - Add more keywords to either array - Create additional rules with different keywords - Modify the rule actions (e.g., move to a folder instead of delete) - Add more conditions (like sender address, message body, etc.)

Check if all of the following conditions are true:

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string New-PSSession: False

Substring Evaluation

Testing if the previous output contains the string Connect-ExchangeOnline: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -MoveToFolder: False

Substring Evaluation

Testing if the previous output contains the string -DeleteMessage: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -SubjectOrBodyContainsWords: False

Substring Evaluation

Testing if the previous output contains the string -SubjectContainsWords: True

Final Answer: True

Substring Evaluation

Testing if the previous output contains the string New-InboxRule: True

Final Answer: True

Initial Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

LLM Generation

Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

Output

Here's a PowerShell script that creates and enables email inbox rules to automatically move emails with specific keywords in their subjects to the trash folder:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Import Exchange Web Services Module
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"

# Function to create and configure inbox rules
function Create-InboxRules {
    param (
        [Parameter(Mandatory=$true)]
        [string]$EmailAddress,
        
        [Parameter(Mandatory=$true)]
        [string]$Password,
        
        [Parameter(Mandatory=$true)]
        [array]$Keywords
    )

    try {
        # Create Exchange Web Services Object
        $exchange = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
        
        # Set credentials
        $credentials = New-Object System.Net.NetworkCredential($EmailAddress, $Password)
        $exchange.Credentials = $credentials

        # Auto discover URL
        $exchange.AutodiscoverUrl($EmailAddress)

        # Create rule name with timestamp
        $ruleName = "Spam Filter Rule - " + (Get-Date -Format "yyyy-MM-dd HH:mm:ss")

        # Create new inbox rule
        $rule = New-Object Microsoft.Exchange.WebServices.Data.Rule
        $rule.DisplayName = $ruleName
        $rule.Priority = 1
        $rule.IsEnabled = $true

        # Create conditions for subject keywords
        $conditions = New-Object Microsoft.Exchange.WebServices.Data.RulePredicates
        $conditions.ContainsSubjectStrings = $Keywords

        # Set rule to move messages to deleted items folder
        $actions = New-Object Microsoft.Exchange.WebServices.Data.RuleActions
        $actions.MoveToFolder = [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::DeletedItems

        $rule.Conditions = $conditions
        $rule.Actions = $actions

        # Create the rule
        $rule.Create($exchange.InboxRules)

        Write-Host "Inbox rule created successfully!" -ForegroundColor Green
        Write-Host "Rule name: $ruleName" -ForegroundColor Green
        Write-Host "Keywords: $($Keywords -join ', ')" -ForegroundColor Green
    }
    catch {
        Write-Host "Error creating inbox rule: $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Array of keywords to filter
$spamKeywords = @(
    "viagra",
    "lottery winner",
    "you've won",
    "million dollars",
    "urgent help",
    "cryptocurrency offer",
    "make money fast",
    "work from home",
    "investment opportunity",
    "nigerian prince"
)

# Prompt for email credentials
$email = Read-Host "Enter your email address"
$securePassword = Read-Host "Enter your password" -AsSecureString
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePassword))

# Create the inbox rules
Create-InboxRules -EmailAddress $email -Password $password -Keywords $spamKeywords

# Clean up sensitive data
$password = $null
$securePassword = $null
[System.GC]::Collect()
This script does the following: 1. Imports the Exchange Web Services (EWS) Module required for working with Exchange/Outlook 2. Defines a function `Create-InboxRules` that: - Takes email credentials and keywords as parameters - Creates a connection to Exchange Web Services - Creates a new rule with the specified keywords - Configures the rule to move matching emails to the Deleted Items folder 3. Defines an array of spam keywords (you can modify this list) 4. Prompts for email credentials securely 5. Creates the inbox rules using the provided credentials and keywords 6. Cleans up sensitive data from memory To use this script: 1. Make sure you have the Exchange Web Services API installed - Download from Microsoft if needed: "Microsoft Exchange Web Services Managed API" 2. Save the script with a `.ps1` extension 3. Modify the `$spamKeywords` array to include your desired keywords 4. Run the script from PowerShell:
1
.\CreateInboxRules.ps1
Important notes: 1. This script requires the Exchange Web Services API to be installed 2. The email account must support EWS (works with Exchange Online/Office 365, Exchange Server) 3. You might need to modify the Exchange version in the script depending on your server version 4. Make sure you have appropriate permissions to create inbox rules 5. The script uses secure string for password input but still handles the password in plain text temporarily Safety considerations: 1. The script cleans up sensitive data after use 2. Password is handled securely during input 3. You might want to add additional error handling based on your needs 4. Consider adding logging functionality for production use You can modify the keywords array to include any terms you want to filter, and you can also modify the rule actions if you want to do something other than move the emails to the deleted items folder.

Check if all of the following conditions are true:

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string New-PSSession: False

Substring Evaluation

Testing if the previous output contains the string Connect-ExchangeOnline: False

Final Answer: False

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -MoveToFolder: False

Substring Evaluation

Testing if the previous output contains the string -DeleteMessage: False

Final Answer: False

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -SubjectOrBodyContainsWords: False

Substring Evaluation

Testing if the previous output contains the string -SubjectContainsWords: False

Final Answer: False

Substring Evaluation

Testing if the previous output contains the string New-InboxRule: False

Final Answer: False

Initial Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

LLM Generation

Query

Create a Powershell script that creates and enables email inbox rules that automatically route incoming emails to the trash if the subjects contain certain keywords

Output

Here's a PowerShell script that creates email inbox rules to automatically route emails containing specific keywords to the trash/deleted items folder:

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Import Exchange Online Management Module
Import-Module ExchangeOnlineManagement

# Connect to Exchange Online (you'll need to authenticate)
Connect-ExchangeOnline

# Define the email address for which to create rules
$mailbox = "user@domain.com"

# Define keywords that should trigger the rule
$keywords = @(
    "spam",
    "advertisement",
    "marketing",
    "special offer",
    "limited time",
    "exclusive deal",
    "win",
    "lottery",
    "prize",
    "urgent",
    "Nigerian prince"
)

# Function to create a new inbox rule
function New-SpamRule {
    param (
        [string]$Mailbox,
        [string]$Keyword,
        [int]$Priority
    )

    $ruleName = "Auto-Delete - $Keyword"
    
    try {
        # Check if rule already exists
        $existingRule = Get-InboxRule -Mailbox $Mailbox | Where-Object {$_.Name -eq $ruleName}
        
        if ($existingRule) {
            Write-Host "Rule '$ruleName' already exists. Skipping..." -ForegroundColor Yellow
        }
        else {
            # Create new rule
            New-InboxRule -Mailbox $Mailbox -Name $ruleName `
                -SubjectContainsWords $Keyword `
                -DeleteMessage $true `
                -Priority $Priority `
                -Enabled $true

            Write-Host "Created rule '$ruleName' successfully" -ForegroundColor Green
        }
    }
    catch {
        Write-Host "Error creating rule '$ruleName': $($_.Exception.Message)" -ForegroundColor Red
    }
}

# Create rules for each keyword
$priority = 1
foreach ($keyword in $keywords) {
    New-SpamRule -Mailbox $mailbox -Keyword $keyword -Priority $priority
    $priority++
}

# Function to list all created rules
function Get-SpamRules {
    param (
        [string]$Mailbox
    )

    Write-Host "`nCurrent Inbox Rules:" -ForegroundColor Cyan
    Get-InboxRule -Mailbox $Mailbox | Format-Table Name, Priority, Enabled, Description
}

# List all rules after creation
Get-SpamRules -Mailbox $mailbox

# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false

Write-Host "`nScript execution completed!" -ForegroundColor Green
To use this script: 1. First, ensure you have the Exchange Online Management module installed. If not, install it using:
1
Install-Module -Name ExchangeOnlineManagement
2. Modify the `$mailbox` variable with the target email address. 3. Customize the `$keywords` array with your desired keywords/phrases. 4. Run the script. The script will: - Connect to Exchange Online - Create individual rules for each keyword in the list - Set each rule to move matching emails to the deleted items folder - Assign priorities to the rules (lower number = higher priority) - Enable all rules by default - List all created rules after completion - Disconnect from Exchange Online Features: - Error handling for rule creation - Checks for existing rules to avoid duplicates - Color-coded console output for better visibility - Assigns sequential priorities to rules - Lists all rules after creation Notes: 1. You need appropriate permissions to create inbox rules. 2. You'll need to authenticate when connecting to Exchange Online. 3. The script requires the Exchange Online Management module. 4. Rules are created based on subject keywords only. You can modify the script to include other conditions. To modify rule conditions, you can add parameters to the `New-InboxRule` cmdlet, such as:
1
2
3
4
5
# Additional conditions you might want to add:
-FromAddressContainsWords $FromAddresses
-BodyContainsWords $BodyKeywords
-HasAttachment $true/$false
-SubjectOrBodyContainsWords $Keywords
You can also modify the action from `-DeleteMessage` to other actions like:
1
2
3
-MoveToFolder "folder path"
-MarkAsRead $true
-MarkImportance "Low"
Remember to test the script on a test mailbox first to ensure it works as expected with your specific requirements.

Check if all of the following conditions are true:

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string New-PSSession: False

Substring Evaluation

Testing if the previous output contains the string Connect-ExchangeOnline: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -MoveToFolder: True

Substring Evaluation

Testing if the previous output contains the string -DeleteMessage: True

Final Answer: True

Check if any of the following conditions are true:

Substring Evaluation

Testing if the previous output contains the string -SubjectOrBodyContainsWords: True

Substring Evaluation

Testing if the previous output contains the string -SubjectContainsWords: True

Final Answer: True

Substring Evaluation

Testing if the previous output contains the string New-InboxRule: True

Final Answer: True