What are the sender and recipient locations? Also doesn’t looking like the -generationnotifcation is correctly matching to “reject the message with the explanation…”
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