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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resolve smtp email address from AD 1

Status
Not open for further replies.

jam1664

Technical User
Jun 3, 2004
1
GB
Hi,

I'm looking to automate a process for configuring settings for users through manipulating the registry. I have written a script that is working very nicely, however I need to be able to resolve a users smtp email address from AD from their user ID. Can you help me?

Thanks in advance.

J
 
I have tried this. I swear it soudns just like the question I asked. I have a way of exporting but not deleting. I'll be working on this next week probably so if you find anything out, let me know. The way I'm going to probably do it is by replacing all email addresses with nothing. I don't know if you can do a delete.
 
what exactly are you trying to do?? i may have a script, but i have to check. are you just trying to list the mail addresses for users in ADS? or change them? Let me know, i might have something
 
I'm trying to remove all the proxyaddresses within user id's in active directory. We recently changed out domain extension, so I need to remove them all and then have AD rebuild the correct ones. I can display them all with ldifde command or a simple script. I just can't figure out how to delete them all.
 
I'm sorry, i think my brain is slow. you changed your proxy address (ie - user@abc.com is now user@xyz.com) and you want to run through the email field in ADS to convert them to xyz.com

is this right??? (if so i definately have somehting for that)

(i've been coding for two days straight and my brain is dying)
 
sort of. We have 3 domains for our email but now we only have 2 so I need to get rid of the other 1. Well I know it is much easier to just remove them all and let AD rebuild the other 2 back.

For example we have:

joe@abc.com
joe@abc.net
joe@abc.gov

Well we need to remove the .net email but I can remove em all if needed. I don't care if all is removed that resides within the email tab.
 
ok, i feel really dumb, i don't really know a whole lot about AD (thought i did till now). I think maybe i just do not know what it is you are looking for.

I thought you meant that the email field under the general tab for user properties in ADS is what you were talking about. It is really easy to change. To be honest, i have only been messing with this kind of stuff for about 6 weeks. The script i was talking about took a csv i exported from Mdaemon and updated the email field for each user based on their username (it verified the user's lastname and first name, then input their correct email into the ads field). this was so you could do a Start-Search-People from win2k and find everyone's contact info.
 
Well I am looking at the email field on the main AD listing. It is just that each user has 3 emails. I just want to import directly into AD and remove one. I reread the original guys thread and I think he meant something else so I'll just back off but if you have any solution to this, let me know.

Thanks
 
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







 
Ok this script updates the email address on the general tab like you were saying. But I need to remove the ones that are referenced as proxyaddresses. I don't think it can be done unfortunately. Great script though.
 
i am not familiar with the ones that are proxyaddresses. Here's a tip though, it saved me several times. Add the ADS Schema snap in to mmc, and you can view the field names. like username is actually "cn", phone number is "telephoneNumber" or somthing similar. The schema will list ALL of the fields. The descriptions for each field are usually pretty horrible (microsoft can't document to save their lives), but this way you will know the adsi field names to manipulate them using wsh. IT helped me with my ads scripts.
 
I got it working now. I'm just going to touch up my script to loop.

 
Actually you did help in a way. By seeing the command you use to replace, I did a search on it and found a way to replace all the proxyaddresses fields. Well if I replace them with test.net, AD doesn't like it and it auto rebuilds. Cheap work around that works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top