To add an email address to each user in the ad because of the job requirement. Our company is using Lotus Notes, and unlike the exchange company, the email address field in AD is empty.
However, the good news is that our emails are regular, Firstname.Lastname@mycompany.com in this form. So simply write a script, read the user account FirstName and LastName value, and then merged into an email address, and then write to the ad in the user account.
function
(1) Read FirstName and Lastname, merge into Firstname.Lastname@mycompany.com, and then write back to email in this field
(2) If you encounter FirstName or LastName is empty, skip the account and show the account on the screen.
(3) After all changes are completed, the total number of accounts that have been updated is displayed.
(4) The script automatically operates on all accounts under a given OU.
Usage
(1) Copy the script below to a text file named Updateemail.vbs
(2) Modify your company's domain name, and your company to store the user Account OU, and save
(3) Then open a command line window and type the following command
cscript Updateemail.vbs
"Disclaimer"
This script is I write, please first in the test environment for debugging, all normal after the use. I do not assume any responsibility for data loss and damage caused by the use of the process.
' ======================start========================
' Modify User Email by FirstName.LastName@mycompany.com
Option Explicit
Dim Strou, Strdomain, Stradsou
Dim objOU, objuser, objRootDSE
Dim I
Dim Charfirstname, Charlastname, Charemail
On Error Resume Next
'===========================================
' Type Contrainer here. The Format is "ou=xxx,ou=yyy"
'===========================================
Strou = "Ou=people,ou=allusers"
Set objRootDSE = GetObject ("LDAP://rootDSE")
Strdomain = Objrootdse.get ("defaultNamingContext")
Stradsou = "ldap://" & Strou & "," & Strdomain
' Connect to OU
Set objOU = GetObject (Stradsou)
WScript.Echo "The emails is added into" & Objou.get ("name") & "OU"
Objou.filter= Array ("user")
I=0
WScript.Echo ""
WScript.Echo "The following AD accounts don ' t have FirstName or LastName:"
For each objuser in objOU
Charfirstname = ""
Charlastname = ""
Charfirstname = Objuser.get ("givenname")
Charlastname = Objuser.get ("sn")
If (charfirstname = null) or (Charfirstname = "") or (Charlastname = null) _
Or (Charlastname = "") Then
WScript.Echo objuser.cn
Else
Charemail = charfirstname+ "." +charlastname+ "@mycompany. com"
objUser.Put "Mail", Charemail
Objuser.setinfo
I=i+1
End If
Next
' Display the ' count
WScript.Echo ""
WScript.Echo "Total record changed:" & I
' ===================end=========================
This article is from the "Delxu Live notepad" blog, please be sure to keep this source http://delxu.blog.51cto.com/975660/276039