![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How to write user's email address into AD? 1.I have a talbe contenting all domain users' email address.which looks like "user ,email" I want to write all domain users' email address into their mail field in AD . Could u tell me how to do it? 2.Why I cannot using "Select * from..." to get the result ,but "Select mail from " is ok? objCommand.CommandText = "SELECT mail FROM 'LDAP://ou=aaa.com.cn,dc=aaa,dc=com,dc=cn' WHERE " _ & "objectCategory='user'" .. .. .. .. WScript.Echo objRecordSet.Fields("mail").Value |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to write user's email address into AD? "£¤£¤£¤" <eagle@xxxxxx> wrote in message news:O0s$ZCq4JHA.6004@xxxxxx Quote: > 1.I have a talbe contenting all domain users' email address.which looks > like "user ,email" I want to write all domain users' email address into > their mail field in AD . Could u tell me how to do it? > > 2.Why I cannot using "Select * from..." to get the result ,but "Select > mail from " is ok? > > objCommand.CommandText = "SELECT mail FROM > 'LDAP://ou=aaa.com.cn,dc=aaa,dc=com,dc=cn' WHERE " _ > & "objectCategory='user'" > . > . > . > . > > WScript.Echo objRecordSet.Fields("mail").Value name, for example the first value would be objRecordset.Fields(0).Value. Of course you have no idea which number corresponds to the "mail" attribute (there are hundreds of user attributes). The only time you should use "SELECT *" is when you are just counting the number of records that meet some condition. You can use a VBScript program to assign the mail attribute, but we need to know a few things: 1. Is your table in a comma delimited text file? Or, is it a database or spreadsheet table? 2. Is "user" the "pre-Windows 2000 logon name", the Distinguished Name, or some other? The script would be easier if the names were Distinguished Names. However, I will assume you have a comma delimited text file (not quotes) and the names are "pre-Windows 2000 logon names". You can use the FileSystemObject to read the text file, and the NameTranslate object to convert the names into Distinguished Names. Note that ADO returns read-only recordsets, so cannot be used to modify objects. A script to assign mail based on a text file could be similar to below: ============= Option Explicit Dim strFileName, objFSO, objFile, strLine Dim strNTName, strMail, objUser, arrItems, strUserDN Dim objRootDSE, strDNSDomain, strNetBIOSDomain Const ForReading = 1 ' Constants for the NameTranslate object. Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_1779 = 1 ' Specify comma delimited file of user names ' and email addresses. strFileName = "c:\Scripts\users.txt" ' Open the file for reading. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFileName, ForReading) ' Determine DNS name of domain from RootDSE. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") ' Use the NameTranslate object to find the NetBIOS domain name ' from the DNS domain name. Set objTrans = CreateObject("NameTranslate") objTrans.Init ADS_NAME_INITTYPE_GC, "" objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) ' Read the file. Do Until objFile.AtEndOfStream strLine = Trim(objFile.ReadLine) ' Skip blank lines. If (strLine <> "") Then ' Parse comma delimited line. arrItems = Split(strLine, ",") strNTName = arrItems(0) strMail = arrItems(1) ' Convert user name from NT format to Distinguished Name. ' Trap error if user not found. On Error Resume Next objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain _ & "\" & strNTName If (Err.Number <> 0) Then On Error GoTo 0 ' User not found. Wscript.Echo "User " & strNTName & " not found!" Else On Error GoTo 0 ' Bind to user object. strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) Set objUser = GetObject("LDAP://" & strUserDN) ' Assign email address. objUser.mail = strMail ' Save changes. objUser.SetInfo End If End If Loop ' Clean up. objFile.Close -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to write user's email address into AD? Thank you very much! Finally I use "objUser.mail = objUser.userPrincipalName" to write the mail field after I understand your script. Anyway,your script is very helpful. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| why my address book always automantic add the email address who send me | Vista mail | |||
| entire email address is displayed in address bar | Vista mail | |||
| Can i migrate/associate http://mynick.spaces.live.com/ web address with my new email address??? | Live Messenger | |||
| Changing old email address to new email address for sending pictur | Vista music pictures video | |||