Skip to content

Instantly share code, notes, and snippets.

@tostka
Last active March 27, 2018 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tostka/1dce3fc2ee802e302afdaf483f1caf32 to your computer and use it in GitHub Desktop.
Save tostka/1dce3fc2ee802e302afdaf483f1caf32 to your computer and use it in GitHub Desktop.
Exchange Script to splice in historical LEDN onto migrated mailboxes, to support reply-to etc on PST migrated email.
# append-x500LEDN-ToMbxEmailAddressess.ps1
<# key snippet from larger script...#>
if(test-path $InputCSV) {
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Loading Input file: $($InputCSV)" ;
$procMbxs=import-csv $InputCSV ;
foreach($pMbx in $procMbxs) {
if($tmbx = get-mailbox -identity "$($pMbx.WindowsEmailAddress)" -ea 0 ){
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):MATCHED:$($pMbx.WindowsEmailAddress)($($pMbx.displayname))=>TO:$($tmbx.WindowsEmailAddress)($($tmbx.displayname))" ;
$x500LEDN = "X500:" + $pMbx.LegacyExchangeDN ;
if ($tmbx.EmailAddresses -notcontains $x500LEDN) {
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):WHATIF:$($whatif):Adding LEDN as X500: `n$($x500LEDN) `nto existing emailaddresses:`n$($tmbx.emailaddresses)" ;
set-mailbox -identity $pMbx.WindowsEmailAddress -EmailAddresses @{Add=$x500LEDN} -whatif:$($whatif);
} else {
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):SKIPPING:Mailbox $($tmbx.windowsemailaddress) already contains $($x500ledn)" ;
} ;
} else {
write-host -foregroundcolor red "$((get-date).ToString('HH:mm:ss')):UNABLE TO MATCH:$($pMbx.WindowsEmailAddress)($($pMbx.displayname))" ;
} ;
"===========`n" ;
} ;
} else {
write-host -foregroundcolor red "$((get-date).ToString('HH:mm:ss')):MISSING InputCsv:$($InputCSV)" ;
} ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment