Skip to main content

Safe Sender Domains

Vorher per Powershell Verbindung zum Exchange Server aufbauen! Danach Powershell Script ausführen und "domainlist.txt" anpassen / erstellen.

# domainlist.txt anlegen und Domains hinterlegen!


# NAME: Add365SafeDomains.ps1




Param(
   [Parameter(Mandatory=$True,Position=1)]
   [string]$ruleName,


   [Parameter(Mandatory=$True)]
   [string]$domainListFilePath
)


#Read the contents of the text file into an array
$safeDomainList = Get-Content $domainListFilePath


#Create a new array and remove all text for each line up to and including the @ symbol, also remove whitespace
$newSafeDomainList = @()
$newSafeDomainList += foreach ($domain in $safeDomainList) 
{
$tmpdomain = $domain -replace ".*@"
$tmpdomain.trim()
}


#If the rule already exists update the existing allowed sender domains, else create a new rule.
if (Get-TransportRule $ruleName -EA SilentlyContinue)
{
"Updating existing rule..."
$safeDomainList = Get-TransportRule $ruleName |select -ExpandProperty SenderDomainIs
$completeList = $safeDomainList + $newSafeDomainList
$completeList = $completeList | select -uniq | sort
set-TransportRule $ruleName -SenderDomainIs $completeList 
}
else
{
"Creating new rule..."
$newSafeDomainList = $newSafeDomainList | sort
New-TransportRule $ruleName -SenderDomainIs $newSafeDomainList -SetSCL "-1"
}