Solved

Creating Users script

Posted on 2006-07-20
1
330 Views
Last Modified: 2010-04-18
Trying to get a script to take information from an excel file and input them into active directory.  They will add if complex passwords are used.  But if complex passwords are not used then it gives an errors that a complex password is needed.

The script being used looks like this:

' UserSpreadsheet .vbs
' Sample VBScript to create User accounts from a spreadsheet
' Author Guy Thomas http://computerperformance.co.uk/
' Version 4.6 - June 2005
' ------------------------------------------------------'
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD, strDesc, StrDis

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'

strOU = "OU=Students, OU=SAJS, OU=03 Schools," ' Note the comma
strSheet = "c:\studenttest.xml"

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
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, 1).Value)
   strFirst = Trim(objExcel.Cells(intRow, 2).Value)
   strLast = Trim(objExcel.Cells(intRow, 3).Value)
   strPWD = Trim(objExcel.Cells(intRow, 4).Value)
   strDesc = Trim(objExcel.cells(intRow, 5).value)
   strDis = Trim(objExcel.cells(intRow, 6).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
   objUser.Put "DisplayName", strDis
   ' objUser.Put "description", strDesc
   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 Sample UserSpreadsheet VBScr
In the domain security settings all the complex password rules are turned off so i can't see that being the problem.  Any suggestions would be great, thanks.
0
Comment
Question by:matt1982
1 Comment
 
LVL 29

Accepted Solution

by:
mass2612 earned 500 total points
ID: 17150208
Hi,

Nice script. Maybe you can try using ChangePassword "", strPWD instead. I've not tried to use SetPAssword in a domain where the complex password requirement is setup in the domain policy.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now