Page 1 of 1 1
Topic Options
#180769 - 2007-09-21 05:31 PM Create User Account
danilda Offline
Fresh Scripter

Registered: 2006-03-01
Posts: 21
Loc: Washington, DC
First off, let me say, I haven't the foggiest idea what I am doing. I need to create user accounts in AD. Borrowed some lines of code from other posting, but can't figure out where I am going wrong. Can someone please help me from my misery?

Thanks.

Code:


dim $domain, $user, $userName, $fullusername, $userdescription
$username = "jdoe"
$fullusername = "Jane Doe"
$userdescription = "test

$Domain = GetObject("LDAP://cn=Users,dc=something,dc=com")
$user = $Domain.Create("user", "ou=" + $userName)
$user.Put("FullName", $FulluserName)
$user.Put("Description", $userDescription)
;$user.SetInfo

$domain = 0
$user = 0

Top
#180772 - 2007-09-21 08:40 PM Re: Create User Account [Re: danilda]
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Get rid of the ";" in front of the "$user.Setinfo".
Apart from that, you mixed up "cn" and "ou" in the 6. and 7. line. They should read:
 Code:

$Domain = GetObject("LDAP://ou=Users,dc=something,dc=com")
$user = $Domain.Create("user", "cn=" + $userName)

You also need(!) to set the SAMaccountname:
 Code:
$User.Put ("sAMAccountName", $username)


That should do it.

You might wanna add:
 Code:
	$user.AccountDisabled = 0
	$user.SetInfo

to unlock the new account, and
 Code:

      $user.SetPassword ($passvariable)
      $user.SetInfo  

to set a password.
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#180775 - 2007-09-21 11:57 PM Re: Create User Account [Re: therob]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Actually, the default user container is CN, not OU.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180778 - 2007-09-23 01:15 AM Re: Create User Account [Re: Les]
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
so, you mean it works both ways? cause mine does... \:\)
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#180815 - 2007-09-25 09:46 AM Re: Create User Account [Re: therob]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
CN is used for objects and folders, OU is Organizational Unit.
It's weird that your script would work calling the user an OU. It shouln't work at all.

Top
#180860 - 2007-09-26 04:30 PM Re: Create User Account [Re: Arend_]
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
 Code:
$Domain = GetObject("LDAP://ou=Users,dc=something,dc=com")
$user = $Domain.Create("user", "cn=" + $userName)

why do i call the user an OU? The OU is called "USERS".


Edited by therob (2007-09-26 04:31 PM)
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#180864 - 2007-09-26 05:04 PM Re: Create User Account [Re: therob]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... you may in fact have an OU called users but it does not change the fact that a vanilla out-of-the-box install of AD has a CN called users.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180865 - 2007-09-26 05:18 PM Re: Create User Account [Re: Les]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Can someone create a OU with the name Users next to the existing cn named Users?
Top
#180875 - 2007-09-26 06:21 PM Re: Create User Account [Re: Witto]
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
Maybe i'm missing something, but apart from the qestion about the USERS-OU, in MS-technet the usage of OU and CN (in the context of creating a user) is displayed exactly like i said:
http://www.microsoft.com/technet/scriptcenter/guide/sas_usr_doig.mspx?mfr=true
So i dont really see the problem.
And yeah, it's correct, my example creates the user in the OU(!) called Users. But as "dc=something,dc=com" indicates, it was just an e x a m p l e.
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#180918 - 2007-09-27 08:05 PM Re: Create User Account [Re: therob]
danilda Offline
Fresh Scripter

Registered: 2006-03-01
Posts: 21
Loc: Washington, DC
Keep getting:

Error: Unknown command [LDAP:]

Top
#180919 - 2007-09-27 08:10 PM Re: Create User Account [Re: danilda]
danilda Offline
Fresh Scripter

Registered: 2006-03-01
Posts: 21
Loc: Washington, DC
Found the problem, missing " on line above.
Top
#180920 - 2007-09-27 08:19 PM Re: Create User Account [Re: danilda]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Those are the small d#mn things that'll get me to wanna throw something out the window sometimes. Started using and editor with colour coding because it was cheaper then buying a new computer every time \:\)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180963 - 2007-09-28 03:28 PM Re: Create User Account [Re: Mart]
danilda Offline
Fresh Scripter

Registered: 2006-03-01
Posts: 21
Loc: Washington, DC
Having a hard time finding the attributes that I need to create user account. Need the following attribute: Enable Account. Also, can I place users in groups by using memberof attribute? Does anyone know where I can get a complete of attributes that will work with kix and LDAP?

thanks -- dee


Edited by danilda (2007-09-28 03:39 PM)

Top
#180964 - 2007-09-28 03:44 PM Re: Create User Account [Re: danilda]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Lots of resources... ADSI Scriptomatic, ADSI resuorce kit, VBS script center, etc. all on the web at Microsoft.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#181167 - 2007-10-05 05:17 PM Re: Create User Account [Re: danilda]
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
 Originally Posted By: danilda
Need the following attribute: Enable Account.

i already wrote that above. Did you read my post at all? :|
 Code:
$user.AccountDisabled = 0
$user.SetInfo


 Originally Posted By: danilda
Also, can I place users in groups by using memberof attribute?

No, but this can:
 Code:
Function addtogroup ($adloginname,$adgroupname)
	
	$grouppath = "LDAP://cn="+$adgroupname+",ou=OuLocationOftheGroup,dc=domain,dc=com"
	$userpath = "LDAP://cn="+$adloginname+",ou=OuLocationoftheUser,dc=domain,dc=com"
	 
	$GroupObj = GetObject($grouppath)
	$UserObj = GetObject($userpath)
	
	$GroupObj.add ($UserObj.ADsPath)
	$GroupObj.SetInfo

EndFunction
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
#182014 - 2007-10-27 03:43 PM Re: Create User Account [Re: therob]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The work is already done for you...

CreateUserAccount UDF from an older thread
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.15 seconds in which 0.071 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org