Powershell script to add many identical transport rules to office365

Hello! I’ve got an txt file with thousands of public domains, separated by commas (for example: domain2.com,domain3.com,domain4.com,domain5.com,domain6.com,domain7.com)

Transport rule can not be more then ~4000 symbols. How can i add many-many identical rules with ps like

New-TransportRule -Name “Untrusted1” -Priority 9 -FromScope NotInOrganization -SenderDomainis domain2.com,domain3.com,domain4.com -PrependSubject "[untrasted]: "

Plz help

Hello Ivan28,

This forum is not for script requests. Please try/test something and present your dad de and any additional questions.

You can simply run loop for example for each domain.

foreach($domain in $DomainList){
   New-TransportRule -Name “Untrusted-$domain” -Priority 9 -FromScope NotInOrganization -SenderDomains $domain -PrependSubject “[untrusted]: ”
}

This will result in Transport rule for every domain.

Hope that helps.