Main Page / Index

' ChangeEmailDomain.vbs
' PLEASE READ: This can really mess up your email addresses. I strongly suggest the you run this in "test mode" first.
' After testing you can remove the comment ' for the beginning of any line starting with 'objMember and changes will
' be written to AD. You should run "real mode" on a test OU before changing you whole live OU. Do one OU at a time.
' I added a filter to change only because some users need to keep their special suffix. Only users
' with an address of will be changed
' strLDAP is the DN of the group you wish to apply the changes to. You can copy and paste the DN from ADSIEDIT
' strDefaultSuffix is the suffix suffix stamped by the recipient policy for the domain the group is in
' strNewSuffix is the custom suffix you wish to replace the default suffix with for strLDAP
' If you need anything more complex than mailnickname as the prefix then you must modify the script
' You will need to create a recipient policy for strNewSuffix with a blank filter so Exchange will accept for delivery
' Suggested usage: cscript ChangeEmailDomain.vbs > changeresults.txt

strDefaultSuffix = ""
strNewSuffix = ""
strLDAP = "LDAP://OU=Users,OU=Austin,DC=ad,DC=yourdomain,DC=com"


On Error Resume Next

Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objOU = GetObject(strLDAP)
ObjOU.Filter= Array("user")
For Each objMember in objOU
         strNickname = objMember.mailnickname
         strEmail = objMember.mail
         aryEmailDomain = Split(strEmail, strNickname)
         if aryEmailDomain(1) = "" then
            ' If the smtp address was already there as a secondary smtp address then delete it
            'objMember.PutEx 4, "ProxyAddresses", Array("smtp:" & objMember.mailnickname & strNewSuffix)
            ' put the smtp address in as a primary then set mail and msexchpoliciesexcluded
            'objMember.PutEx 3, "ProxyAddresses", Array("SMTP:" & objMember.mailnickname & strNewSuffix)           
            'objMember.Put "mail", objMember.mailnickname & strNewSuffix
            'objMember.Put "msexchpoliciesexcluded", "{26491CFC-9E50-4857-861B-0CB8DF22B5D7}"
            ' delete the old primary
            'objMember.PutEx 4, "ProxyAddresses", Array("SMTP:" & objMember.mailnickname & strDefaultSuffix)
            ' add the old primary back as a secondary
            'objMember.PutEx 3, "ProxyAddresses", Array("smtp:" & objMember.mailnickname & strDefaultSuffix)
            wscript.echo "changed " & objMember.mailnickname & strDefaultSuffix & " to "_
                & objMember.mailnickname & strNewSuffix
            wscript.echo "skipping " & strEmail
         end if

Any technical comments or questions about these pages
should be sent to:

Design & Presence by Best in Texas Web Services

Document made with Nvu