Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cant enable user account with script

Status
Not open for further replies.

rlee80

MIS
May 20, 2004
10
GB
Hi all,

Can anyone help me with this error, I am trying to create OU's from an excel spreadsheet which works ok using the script below.
I am also trying to create users in the relevant OU's which also works ok but when the accounts are created they are all disabled even though I think I enable them in the
script using the line objUser.AccountDisabled = False

Here is the script:

Dim objExcel, objWorkbook, objOU, objUser, objDomain
Dim intRow

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\ou's.xls")

On Error Resume Next

intRow = 2

'create ou's from data in spreadsheet

Do Until objExcel.Cells(intRow,1).Value = ""
Set objDomain = GetObject("LDAP://dc=testing,dc=com")
Set objOU = objDomain.Create("organizationalUnit", "ou=" & objExcel.Cells(intRow, 1).Value)
objOU.Setinfo
intRow = intRow + 1
Loop

objExcel.Quit

Set objWorkbook = objExcel.Workbooks.Open("D:\NewUsers.xls")

intRow = 2

'create users from data in spreadsheet and put in relevant ou's

Do Until objExcel.Cells(intRow,1).Value = ""
Set objOU = GetObject("LDAP://ou=" & objExcel.Cells(intRow, 5).Value & ", dc=testing,dc=com")
Set objUser = objOU.Create("User", "cn=" & objExcel.Cells(intRow, 1).Value)
objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
objUser.GivenName = objExcel.Cells(intRow, 3).Value
objUser.SN = objExcel.Cells(intRow, 4).Value
objUser.AccountDisabled = FALSE
If Err.Number <> 0 Then
Wscript.Echo Err.Number & "--" & Err.Description
Err.Clear
End If
objUser.SetInfo
intRow = intRow + 1
Loop

objExcel.Quit


This error is reported when the script is run on a windows 2000 domain controller logged on as Admin.

The Active Directory Property cannot be found in the cache


Regards


Rob
 
I suggest to comment out the On Error Resume Next instruction, just to see if you don't have error earlier.
I wonder why you quit excel before opening the 2nd spreadsheet ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I had a similar problem when I wrote a script to create user accounts and the way round it for me was to

objUser.SetInfo
Then
objUser.AccountDisabled = FALSE
Then
objUser.SetInfo
again

Hope this helps
 
I had to do this:

Code:
		objNewUser.SetInfo

		If PromptYesNo("Enable Account Now?") Then
			Const ADS_UF_ACCOUNTDISABLE = 2
			Dim intUAC : intUAC = objNewUser.Get("userAccountControl")
			intUAC = intUAC AND &h7d
			objNewUser.Put "userAccountControl", intUAC
			objNewUser.SetInfo
		End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top