#85186 - 2002-03-01 08:50 PM
Unable to create a user in AD
|
Jonathan
Lurker
Registered: 2002-01-04
Posts: 3
Loc: Richmond, BC Canada
|
I am trying to create a user in a 2000 domain Active Directory. Ideally, I would like to create the user in a specific OU, however, I can't seem to get the user to appear anywhere (even in the default area "USERS").I am using the following code, but remember, I am new to the COM portion of KIX 2001... code:
$DomainObj = GetObject("LDAP://domain") ;Connect to domain IF NOT $DomainObj = 0 ;Confirm connection $UserObj = $DomainObj.Create("user", "jdoe") ;Create a new user IF NOT $UserObj = 0 ;Confirm new user $UserObj.CN = "John Doe" ;Write all information to user $UserObj.SamAccountName = "Jdoe" $UserObj.UPN = "Jdoe@sd38.ca" $UserObj.Password = "Temporary" $UserObj.givenName = "John" $UserObj.sn = "Doe" $UserObj.SetInfo ;Save changes to account ELSE ? @ERROR ? ? @SERROR ENDIF ELSE ? @ERROR ? ? @SERROR ENDIF
The results of this code, seem to be good. There are no errors, and the code runs through to completion. The user, however, does not appear in the Active Directory. All references, that I can find, say that a user in 2000 only requires a Common Name (CN) and a Sam Account Name to be created. Help Please... --Jonathan [ 01 March 2002: Message edited by: Jonathan ]
|
|
Top
|
|
|
|
#85187 - 2002-03-07 01:30 PM
Re: Unable to create a user in AD
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Jonathan, The method you use is good for NT4 domain (yes, using the ad client only on a NT workstation allow you to create user on a NT4 domain), but not complete for Active Directory domain. First, you must to bind to a container on the AD domain, such as a OU or the Domain Users folder Only after that, you can create user in the domain.
For example, you have this path : My OU/the domain where I am/Office.com you want to create users in My OU (could also be Domain users or any other container) first, you have to get a handle to My OU : $myou=getobject("LDAP://My OU/the domain where I am/Office.com") Other possible naming are getobject("LDAP://My OU" + getobject("LDAP://rootDSE").ADSPath) this one is more generic
Now you have your container, you can create your users within : $myou.Create("user", "jdoe") ...
For the method you used, i suggest you to get a look on the root of the current domain in AD, if the users where created, you'll find them here
Beware for this sample, i wrote this one as-is, so you may need to test some part
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#85188 - 2002-03-07 07:31 PM
Re: Unable to create a user in AD
|
Jonathan
Lurker
Registered: 2002-01-04
Posts: 3
Loc: Richmond, BC Canada
|
Thank you.
Your suggestions worked like a charm!
|
|
Top
|
|
|
|
#85189 - 2002-03-12 03:05 PM
Re: Unable to create a user in AD
|
Joerg
Fresh Scripter
Registered: 2002-03-12
Posts: 7
Loc: Burgdorf, Switzerland
|
Hi Guys
I am new on this BBS and not yet very familiar with kix. Anyway, I have the same task as described above. Unfortunately appears after the obj.SetInfo statement the following error message from @SERROR
COM exception error "SetInfo" ((null) - (null)) [1/1]
Does someone know this problem? Thanks for reponse
Cheers, Jörg
|
|
Top
|
|
|
|
#85190 - 2002-03-12 08:01 PM
Re: Unable to create a user in AD
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Joerg, Are you using the same script ? if it's not the case, please post it here Before anything else, are you logged with Admin powers to run this script ? it's necessary for doing such changes
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#85191 - 2002-03-13 10:35 AM
Re: Unable to create a user in AD
|
Joerg
Fresh Scripter
Registered: 2002-03-12
Posts: 7
Loc: Burgdorf, Switzerland
|
Hi Alex
Thanks for response. The code for the script is almost the same as in the sample above. Below you'll find the full code: code:
$MyOU = getobject("LDAP://OU=TestJK,DC=area,DC=company,DC=com")
IF NOT $MyOU = 0 ;check the connection
$UserObj = $MyOU.Create("user", "TestJK") ;create the new account IF NOT $UserObj = 0 ;check whether the account has created $UserObj.CN = "TestJK" $UserObj.SamAccountName = "TestJK" $UserObj.UPN = "TestJK@gmaare.migros.com" $UserObj.Password = "TestJK" $UserObj.SetInfo ;save the changes ? @ERROR ? @SERROR ? $UserObj.CN ELSE ? @ERROR ? @SERROR ENDIF ELSE ? @ERROR ? @SERROR
ENDIF
I am testing on XP Workstation and I am logged in as Domain Administratior. When I try to do the same with the WinNT:// provider, I get the user created, however, just on the local machine. I guess that there must be a security problem with LDAP:// so I am not sure whether I have to provide a separat user and password. Thanks for your help.
Cheers, Jörg
|
|
Top
|
|
|
|
#85192 - 2002-03-14 12:25 AM
Re: Unable to create a user in AD
|
Joerg
Fresh Scripter
Registered: 2002-03-12
Posts: 7
Loc: Burgdorf, Switzerland
|
Hi Guys
For all those who are interested in. The problem described above has been solved with the following changes of code: code:
Previous Code...
$UserObj = $MyOU.Create("user", "CN=TestJK") ;create the new account IF NOT $UserObj = 0 ;check whether the account has created ? "Object created" $UserObj.SamAccountName = "TestJK" $UserObj.UPN = "TestJK@gmaare.migros.com" $UserObj.Password = "TestJK" $UserObj.SetInfo ;save the changes ? @ERROR ? @SERROR ? $UserObj.CN ELSE ? @ERROR ? @SERROR ENDIF ...
I am not sure what the problem actualy caused. I just did change the obj.create statement with the CN= expression and now it works fine. It looks also to me that properties has to change in certain order. However, I just started with ADSI and I am not sure whether my statement is correct or not. Anyway, hope it helps some others who also fight with that problem.
Cheers, Jörg
Bye the way: Does someone know a good ressource on internet to get detailes about the ADs Objects?
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|