if the address is simple username@abc.com; username@abc.gov
then all you have to do is this: write a script that runs through the ads, and creates an excel spreadsheet, then use another script to run through the excel, and update the emails. Here is a script that takes an xl spreadsheet, and updates email addresses in ads.
the spreadsheet looks like this:
Mailbox FullName Domain
jsmith John Smith domain.com
jtaylor Jen Taylor domain.com
jdoe John Doe domain.com
The code is a combination of different people's code, i am sorry that I cannot remember everyone that helped, most are here at Tek-tips. You can reverse engineer this script to run in ads and write to xl, then update the fields.
const xlFile = "C:/Folder/File.xls"
const xlSheet = "[Speadsheet1$]" 'Name of spreadsheet
const adOpendynamic = 2
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenStatic = 3
const adOpenUnspecified = -1
Const adLockBatchOptimistic = 4
const adLockOptimistic = 3
const adLockPessimistic = 2
const adLockReadOnly = 1
Const adLockUnspecified = -1
Const ADS_Update = 3
Dim conXL, cmdXL, rstXL
Dim intColumn, intRow, strComment
Set conXL = CreateObject("ADODB.Connection")
Set cmdXL = CreateObject("ADODB.Command")
Set rstXL = CreateObject("ADODB.Recordset")
conXL.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlFile & ";Extended Properties =""Excel 8.0;HDR=Yes"""
cmdXL.ActiveConnection = conXL
cmdXL.CommandText = "SELECT * FROM " & xlSheet
Dim conADS, rstADS, cmdADS, strADS, strDefaultDomainNC
Dim strCN, strLocation, strphone, strFax, strOtherPhone, strFull
Dim xlCheck
'Get Default namaing context from ads server
strDefaultDomainNC = GetObject("LDAP://RootDSE").Get("DefaultNamingContext")
Set conADS = CreateObject("ADODB.Connection")
conADS.Provider = "ADsDSOObject"
conADS.Open "Active Directory Provider"
Set cmdAds = CreateObject("ADODB.Command")
Set cmdADS.ActiveConnection = conADS
strADS = "SELECT samAccountName, givenName, sn, adsPath" & _
" FROM 'LDAP://" & strDefaultDomainNC & "'WHERE objectClass= 'user'"
cmdADS.CommandText = strADS
'Open connection to ADS Server
Set rstADS = cmdADS.Execute
Do While Not rstADS.EOF
Set objUser = GetObject(rstADS.Fields("ADsPath").Value)
'Wscript.Echo objUser.cn
If len(objUser.sn) > 0 Then
strCN = objUser.samAccountNAme
strFull = objUser.cn
' To debug
' Wscript.Echo strCN & " " & strLocation
' This checks to see if the user in ADS has a lastname, this will prevent you from updating "users" that are just generic
' IE - like admin or quest, etc.
If len(strFull) > 0 Then
'Wscript.Echo strCN & " " & strLocation
Set rstXL = cmdXL.Execute
Do While Not rstXL.EOF
xlCheck = rstXL.Fields(1).Value
strMail = rstXL.Fields(0).Value & "@" & rstXL.Fields(2).Value
'Wscript.Echo xlCheck & " " & strFull
If Trim(xlCheck) = strFull Then
objUser.Put "mail", strMail
'Wscript.Echo strPhone & " " & objUser.telephoneNumber
objUser.SetInfo
End IF
'Wscript.Echo strOtherPhone & " " & objUser.otherTelephone
rstXL.MoveNext
Loop
End If
End If
If Err.number > 0 Then
Wscript.Echo Err.number & " " & Err.Description
End If
rstADS.MoveNext
Loop
Wscript.Echo "DONE"
conXL.Close
conADS.Close