MIM Galsync: PowerShell to Export SMTP Addresses from the proxyaddress field

Here is what I want to do

  1. I want to test joining existing contacts in a Directory with mailboxes about to be imported by MIM Galsync from another from another directory. So I have created the mailboxes in the lab and now I want to add the SMTP proxy addresses of the mailboxes.
  2. Export all the SMTP addresses of mailboxes in an OU.
  3. Do not export the primarySMTP address.
  4. Export the mail address as well. I want each record to have the “mail, smtpaddress”. I am going to use the mail address to find the mailbox.
  5. Update the account [created in another environment] proxy address with all the SMTP addresses
  6. I don’t want to use any Exchange commands or EMC, I don’t have access to exchange, I want to do it all with AD commands.

Solution 1: Export the SMTP addresses as single records

$fileName = “D:\temp\tlkmbxSMTPaddress.txt”

$fileObject = New-Item $fileName -type file -force


$evt_string | Out-file $fileObject -encoding ascii -Append

$myusers=Get-ADUser –Filter * –SearchBase “OU=Denver,OU=ContosoUsers,DC=tlktechnology,DC=net” –Properties mail,proxyaddresses

ForEach($myuser in $myusers){

$userproxys = $myuser.proxyaddresses

ForEach($userproxy in $userproxys){

If ($userproxy -cmatch “smtp:”){

$evt_string= $myuser.mail + “;” + $userproxy

$evt_string | Out-file $fileObject -encoding ascii -Append




Solution 2: update the records in another environment

Update Proxyaddress of Mbx

Import-CSV c:\temp\tlksmtpaddr.csv -delimiter “;” | ForEach-Object {$mym = $_.mail;$MyMbx=Get-AdObject -Filter {mail -eq $mym} -searchbase “OU=DenverUsers,OU=Contoso,DC=tlkenterprise,DC=net”; Set-ADObject -instance $MyMbx; Set-ADObject -identity $myMbx -add @{Proxyaddresses=$_.smtpaddr}}