Q. How can I use a script to bulk-mail-enable users?

A. I modified the script in the FAQ "How can I use a script to mail-enable a user--that is, give the user email address attributes in Active Directory (AD)?" to read from a text file that contains three values per line: the user's distinguished name (DN), email address prefix, and nickname. A pipe (|) character delimits the values, so the file format looks like

&ltuser's DN&gt|&ltemail address prefix&gt|&ltuser's nickname&gt

Here's an example of a file that a script could read:

cn=no mail,cn=users,dc=demo,dc=local|nomail|No mail
cn=no mail2,cn=users,dc=demo,dc=local|nomail2|No mail2

Save these lines in a file--for example, d:\temp\tomailenable.txt. Then, run the following blkmailenable.vbs script (a modified version of mailenable.vbs) to read and process the entries from the file. (Some lines are wrapped because of space constraints.) You can download the script at Code.

Dim sTarget, sProxy, sUser

Const ForReading = 1

Set oFSO = CreateObject("scripting.filesystemobject")
Set oTF = oFSO.OpenTextFile("d:\temp\tomailenable.txt", _
  ForReading, True)
Do While oTF.AtEndOfStream  True
sLine = oTF.ReadLine
aLine = split(sline, "|", -1, 1)
sDN = aLine(0)
sMail = aLine(1)
sMailNick = aLine(2)

On Error Resume Next

sUser = "LDAP://" & sDN

WScript.Echo sUser

Set oUser = GetObject(sUser)
oUser.put "mail", sMail & "@netscape.savilltech.com"
oUser.put "mailnickname", sMailNick
oUser.put "DisplayName", sMailNick
oUser.put "proxyAddresses", Array("SMTP:" & sMail & _
  "@netscape.savilltech.com", "smtp:" & sMail & "@savilltech.com")
oUser.put "targetAddress", "SMTP:" & sMail & _

Blkmailenable.vbs opens the file specified in the oTF variable and reads one line at a time. For each line in the file, the script connects the username that's specified by the DN and creates two email addresses for the user: a primary address of &ltemail prefix&[email protected] and a secondary address of &ltemail prefix&[email protected]

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.