Сам скрипт:
_______________________________________
_______________________________________
' UserSpreadsheet .vbs
' Sample VBScript to create User accounts from a spreadsheet
' ------------------------------------------------------'
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD, strDN, srtCompany, strEma, strPhone, strUPN, strL, strST, strAddress, strTitle, stripPhone, strOffice, strDep, strmobile
' -----------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -----------------------------------------------'
strOU = "OU=Accounts ," ' Note the comma
strSheet = "D:\work\scripts\AD\Users\CR.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
'Set objRootLDAP = GetObject("LDAP://dc=ent, dc=com")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 5).Value)
' Additional Info
strDN = Trim(objExcel.Cells(intRow, 6).Value)
srtCompany = Trim(objExcel.Cells(intRow, 7).Value)
strEma = Trim(objExcel.Cells(intRow, 8).Value)
strPhone = Trim(objExcel.Cells(intRow, 9).Value)
strUPN = Trim(objExcel.Cells(intRow, 10).Value)
strL = Trim(objExcel.Cells(intRow, 11).Value)
strST = Trim(objExcel.Cells(intRow, 12).Value)
strAddress = Trim(objExcel.Cells(intRow, 13).Value)
strTitle = Trim(objExcel.Cells(intRow, 14).Value)
strdep = Trim(objExcel.Cells(intRow, 15).Value)
'strmobile = Trim(objExcel.Cells(intRow, 16).Value)
strOffice = Trim(objExcel.Cells(intRow, 16).Value)
' Build the actual User from data in strSheet.
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.givenName = strFirst
objUser.sn = strLast
' Additional Info
objUser.displayName = strDN
objUser.userPrincipalName = strUPN
objUser.Company = srtCompany
objUser.mail = strEma
objUser.telephoneNumber = strPhone
objUser.l = strL
objUser.st = strST
objUser.streetAddress = strAddress
objUser.title = strTitle
objUser.Department = strdep
objUser.physicalDeliveryOfficeName = strOffice
'objUser.mobile = strmobile
'objUser.Department = strDep
objUser.SetInfo
' Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.Quit
WScript.Quit
' End of free example UserSpreadsheet VBScript.
_________________________________________________
В excel-файле столбики должны соответствовать номеру! (то есть если атрибут не заполнен, то он исключается со скрипта , если столбик удален с файла, то номирация должна сдвинуться... не может идти атрибут 5 потом 10... и т.д.)
Пример файла.
в данной картинке есть ошибка... там где номер телефона, колонка номер 7, должно быть 7... дальше 8
в скрипте соответственно необходимо исправить тоже нумерацию в этих строках.
strPhone = Trim(objExcel.Cells(intRow, 9).Value)
strUPN = Trim(objExcel.Cells(intRow, 10).Value)
должно быть 7 и 8...
и так далее. или не смещать колонки.