Mail flow rule PS help

Looking for some guidance on this one. The settings in the image are what I’d like to get done in PS

image
This is what I’ve got:
$Name = “Prevent auto forwarding of email to external domains”

$Notification = “Auto-forwarding email outside this organization is prevented for security reasons.”

New-TransportRule -Name $Name -GenerateNotification $notification -MessageTypeMatches “autoforward”

What are the sender and recipient locations? Also doesn’t looking like the -generationnotifcation is correctly matching to “reject the message with the explanation…”

Appreciate your assistance.

I’ll caveat this by saying that I’m not an Exchange admin and don’t have a M365 environment to test against. Looking at the help, something like this should work:

$TransportRuleParams = @{
    Name                    = 'Prevent auto-forwarding of e-mail to external domains'
    FromScope               = 'InOrganization'
    SentToScope             = 'NotInOrganization'
    MessageTypeMatches      = 'AutoForward'
    RejectMessageReasonText = 'Auto-forwarding email outside this organisation is prevented for security reasons.'
}

New-TransportRule @TransportRuleParams
1 Like