Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing SMTP addresses with VBscript

Status
Not open for further replies.

nmisys

Technical User
Aug 9, 2002
2
GB
Hi,

I want to modify the smtp addresses for a large number of users in our 5.5 exchange setup. Since there is too many to do manually I wanted to use vbscript.

I've looked around and found :

<
but try as I might I can't get it to work. It gets to the line :

Set objMSPrivMDB = objMyIADs.OpenDSObject(strMSPrivMDBPath, strUserName, strPassword, 0)

but then fails with a "An operations error occured" error message.

Does anyone have any code that would allow me to query the current smtp addresses and/or change them?

Any information gratefully received.

Thanks
nmi
 
Is this Exchange 5.5 in an NT 4 domain?

Are you trying to modify a primary or secondary smtp address?

The primary smtp address is stored in the "mail" attribute of the user object in the 5.5 directory. In AD it's "mailnickname". In either, all addresses are also stored in a flat list on the "proxyaddresses" attribute.

The particular line is trying to do an LDAP bind to I assume the 5.5 directory.


gives another example of an ldap bind to the 5.5 directory.
 
Thanks for the reply.

It's Exchange 5.5 in a Windows 2000 environment.

I'm trying to modify both the primary and secondary SMTP addresses.

It does seem that trying to get it to 'bind' is the problem. Have gone through a lot of the code on that page but sadly still get the error.

I'm sure there must be an easy answer to this, I just wish I knew what it was!!

Any other info gratefully appreciated.
 
Another alternative is to loose VBScript and just import with a customised .csv file. I did just this a little while back and it involved a bit of admin and excel manipulation but it worked very well.
This should get you started:


*****************************************
Your mouse has moved - reboot for changes to take effect
 
Windows 2000 is way easier. You can mangle the AD attributes of the user at will via script. Don't worry about binding to the 5.5 DS, as long as the ADC CA is two way.


Anyway, a while back I posted a script that does parses through nested groups and changes the smtp address for all members of the group. Try this:

Code:
' Quick and dirty script to remove the default primary smtp address,set a new, and put the old one back as a
' secondary for each member of a nested group
' Author - fullbrij@comcast.net
' Creation date - 2/12/2004
'
'
' --------------------------------------------- SCRIPT CONFIGURATION --------------------------------------------------
'
'
' strGroupDN 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 strGroupDN
'
' 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
'
strGroupDN = "CN=Test Group,OU=Information Technology,OU=Users,OU=Corporate Office,DC=child,DC=mycompany,DC=com"  
strDefaultSuffix = "@permutation1.com"
strNewSuffix = "@permutation2.com"
'
'
' ----------------------------------------------- END CONFIGURATION ---------------------------------------------------
'
'
' create the dictionary and start stamping
set dicSeenGroupMember = CreateObject("Scripting.Dictionary")
StampMembers "LDAP://" & strGroupDN, dicSeenGroupMember
'
Function StampMembers (strGroupADsPath, dicSeenGroupMember)
'
   set objGroup = GetObject(strGroupADsPath)
   '
   for each objMember In objGroup.Members
   '
      ' if the member is a user then stamp it
      if objMember.Class = "user" 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
      end if
      '
      ' if it is a group then expand the group recursively
      if objMember.Class = "group" then
      '
         if dicSeenGroupMember.Exists(objMember.ADsPath) then
            ' do nothing to avoid looping if we already stamped it
         else
            ' add it to the dictionary and stamp it
            dicSeenGroupMember.Add objMember.ADsPath, 1
            StampMembers objMember.ADsPath, dicSeenGroupMember
         end if
         '
      end if
      '
   next
   '
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top