'
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 @maindomain.com because some users
need to keep their special suffix. Only users
' with an address of xxxx@maindomain.com 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
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) = "maindomain.com"
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)
'objMember.SetInfo
' 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}"
'objMember.SetInfo
' delete the old primary
'objMember.PutEx 4, "ProxyAddresses",
Array("SMTP:" & objMember.mailnickname &
strDefaultSuffix)
'objMember.SetInfo
' add the old primary back as a secondary
'objMember.PutEx 3, "ProxyAddresses",
Array("smtp:" & objMember.mailnickname &
strDefaultSuffix)
'objMember.setinfo
wscript.echo "changed " &
objMember.mailnickname & strDefaultSuffix & " to "_
&
objMember.mailnickname & strNewSuffix
else
wscript.echo "skipping " &
strEmail
end if
Next
Any technical comments or questions about these pages
should be sent to: beissner@bestintexas.com