ADSI Script problem

  • Thread starter Thread starter Chai
  • Start date Start date
C

Chai

Hi Michael Holzemer and others,

I create a script (follow TechNet guide) that will read a
list a users and other fields in the MsSQL table then
check the Active Directory to see whether if the user
exist. If no, then it will create the user and insert the
value for the fields (which I create few attributes - AD
Schema Extending).

When I run the script below, i receive an error
message "Server unwilling to ptocess the request". Can
anyone help?

Thanks.

===========================================================
Sub CheckUser
Dim oUser, oDomain, found
found = 0

Set oDomain = GetObject("LDAP://dc=mycompany,dc=com")
oDomain.Filter = Array("user")

For Each oUser In oDomain
If LCase(oUser.Name) = LCase(sUserName) Then
found = 1
End If
Next
if found = 0 then
call CreateUser
end if
End Sub

'---------------------------------------------------------

Sub CreateUser
Dim oUser, oDomain

Set oDomain = GetObject(""LDAP://dc=mycompany,dc=com")
Set oUser = oDomain.Create("user", sUserName)
oUser.SetPassword "password"
ouser.FullName = fname
ouser.Description = fcourse
oUser.company = fintake
ouser.Intake = fintake
ouser.sessionjoint = fsessjoin
ouser.currentsession = fcurrsess
ouser.status = fstatus
ouser.withdrawday = fwdrdt
oUser.SetInfo
oUser.AccountDisabled = FALSE
WScript.Echo "Account created for", sUserName, "in",
sDomainName
End Sub

'---------------------------------------------------------
sub CallDatabase

Set adoDataConn = CreateObject("ADODB.Connection")
adoDataConn.Open "test"

strQuery = "SELECT * FROM table1;"
Set RS = adoDataConn.Execute(strQuery)

while not RS.eof

sUserName = rs.Fields("fregkey")
fname = rs.Fields("fname")
fcourse = rs.Fields("fcourse")
fintake = rs.Fields("fintake")
fsessjoin = rs.Fields("fsessjoin")
fcurrsess = rs.Fields("fcurrsess")
fstatus = rs.Fields("fstatus")
wdrdt = rs.Fields("fwdrdt")

Call QueryForUser
RS.MoveNext
wend

RS.Close
adoDataConn.Close
End Sub

'---------------------------------------------------------

Dim sUserName, sDomainName, fregkey, fname, fcourse,
fintake, fsessjoin, fcurrsess, fstatus,fwdrdt

call CallDatabase
 
First of all you will need to change your Create User sub. Starting with
syntax you will need the put method to change properties.
'// You must have this line to create a user account in AD
objuser.put "sAMAccountName", lcase(sLogon)

'// Examples of setting some properties
objuser.put "DisplayName", sCN
objuser.put "name", sCN

'// You must run a setinfo before setting the password in a domain
objUser.SetInfo
objUser.setpassword "nasa"

'// Then end with a setinfo
objuser.accountdisabled = FALSE
objUser.SetInfo

Download this ADSI Scriptomatic tool to get more information
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/tools/admatic.asp
 
Hi Michael Holzemer,

I still receive the same error!

Can I use a variable name to replace the following
statement <Set objLeaf = objContainer.Create
("User", "cn=UserNo"> like this <Set oUser = oDomain.Create
("user", sUserName)> then only put the
<ouser.put "sAMAccountName", lcase(sUserName)>?

Can I use WINNT:\\ rather then LDAP:\\

Thanks again.
 
Back
Top