Scenario: You have to convert the LegacyExchangeDN that is being provided to you in bounce back emails with the special charter formatting into an X500 address. This may need to be done if mailboxes are disabled and recreated as new mailboxes or when performing migrations.
From the bounce back message, copy and paste the address into the $Addr variable below and then execute this script:
#Edit the $Addr Variable
$Addr = "IMCEAEX-_O=TEST+20ENTERPRISE+20EXCHANGE_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=4bd8a35a90e2441a4587635898d62f9f-s@domain.com"
#Run the following against the variable
$Addr = $Addr -replace "IMCEAEX-",""
$Addr = $Addr -replace "@.*$",""
$Addr = $Addr -replace "_","/"
$Addr = $Addr -replace "+20"," "
$Addr = $Addr -replace "+28","("
$Addr = $Addr -replace "+29",")"
$Addr = $Addr -replace "+2C",","
$Addr = $Addr -replace "+5F","_"
$Addr = $Addr -replace "+40","@"
$Addr = $Addr -replace "+2E","."
$Addr= “X500:$Addr”
Write-Host $Addr
#Add the Email Address to the Mailbox
set-mailbox usera -emailaddresses @{Add=$Addr}
Nice script, thanks.
LikeLike