Snippet to build a TLS connector in Exchange Online for a list of domains

Some organisations, in particular German ones, require encryption between your Exchange Online mail servers and their mail servers. This can be enforced by adding their domains to an outbound TLS connector in Office 365.

In my case, this had to be enforced (the default is oppertunistic). If you get a long list, you’ll want to script this with the following snippet. Remember to make sure the first line of your CSV has the header/colum name ‘domain’ 🙂


#Author: Jos Lieben
#Help: www.lieben.nu
$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber -DisableNameChecking

$connector = Read-Host "Type the name you wish to give this connector"
$csv = Read-Host "Type the path to the file with TLS domains"

$domains = Import-CSV -LiteralPath $csv

$newDomains = @()
foreach($domain in $domains){
$ND = [String]$domain.domain
$ND = $ND.Trim()
$newDomains += $ND
}

try{
New-OutboundConnector -Name $connector -recipientdomains $newDomains -ConnectorType "Partner" -TlsSettings "CertificateValidation" -ErrorAction Stop
}catch{
Write-Error "Failed to modify outbound connector $connector $($Error[0])"
}

6
Leave a Reply

avatar
1 Comment threads
5 Thread replies
3 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
AustinJosMike H Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
Mike H
Guest
Mike H

I receive the following error when executing this snippet: Cannot process argument transformation on parameter ‘RecipientDomains’. Cannot convert value ” ” to type “Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.SmtpDomainWithSubdomains]”. Error: “Cannot convert value “” to type “Microsoft.Exchange.Data.SmtpDomainWithSubdomains”. Error: “”” isn’t a valid SMTP domain.”” + CategoryInfo : InvalidData: (:) [New-OutboundConnector], ParameterBindin…mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-OutboundConnector + PSComputerName : outlook.office365.com It seems like nothing is being passed to the $newDomains variable. My CSV file has data in it.