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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active directory scripting users

Status
Not open for further replies.

3wsparky

IS-IT--Management
May 25, 2003
121
GB
Right i want to be able to give some limited power to the admin staff at my work so that they can add users to the active directory server, simple

the problem i have is i want the vbs to also add a right logon script and profile path etc.

i have got this far and have tried all sorts of ways to get that infomation into the account but am yet to find the solution !!!!!!!!!!!!!! AHHHH driving me mad.
i can add the user to AD and it all works other than there is no loginscript.bat applied or c:\myprofile applied
im aware that the script now has no way of making this info as it has been removed to stop confusion , and to be honest i dont think the method i had was much cop anyhow.

script as follows

dim objuser
StrFulluser = inputbox("Full Name")
Struserin = inputbox("Username")
StrDescription = inputbox("Account Decription")
StrDomain = inputbox("Domain To Add user to")
StrPassword = inputbox("Enter The Users Password")

strprofile = inputbox("profile")
strscript = inputbox("script")
strhomedir = inputbox("home")
Adduserconfig Struserin,StrDomain,Strprofile,Strscript,Strhomedir
sub Adduserconfig(strUser,strDomain,strProfile,strScript, strHomedir)
Dim Computer
Dim User
Set Computer = Getobject("WinNT://" & strDomain)
Set User = computer.create("User",strUser)
User.fullname = strFullname
User.Description = strDesc
call User.SetPassword(strPassword)
User.setinfo
Set User = nothing
Set computer = nothing
End sub




 
Hi 3wsparky,

I use the 'Display User Information' script by Ralph Montgomery
Link
as a reference.
I think you will find your answer here...

Hope this helps...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Hi , Thats a fantastic script

I have been proding and poking at it and can't seem to get it to add my script tho :(

but i will be keeping that to hand for a later date .

many thanks for that

I just can't get the script box of ad to show what i entered into the input box in the vbs ?

any ideas anyone ?

 
instead of using
User.fullname = strFullname
User.Description = strDesc

you can also use
Set objUser = objOU.Create("user", "cn=" & strUser)
objuser.put "givenName", strFullname
objuser.put "description", strDesc
objUser.put "homedrive", strHomeDrive
objUser.put "homeDirectory", strHomeDir
objUser.put "ScriptPath", strScript
objUser.put "ProfilePath", strProfile
objUser.SetInfo

Hope this does the trick
(very nead scripts to be found Here)

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Right thanks for that

current script is as follows


dim objuser
StrFulluser = inputbox("Full Name")
Struser = inputbox("Username")
StrDescription = inputbox("Account Decription")
StrDomain = inputbox("Domain To Add user to")
StrPassword = inputbox("Enter The Users Password")

strprofile = inputbox("profile")
strscript = inputbox("script")
strhomedir = inputbox("home")
Adduserconfig Struser,StrDomain,Strprofile,Strscript,Strhomedir
sub Adduserconfig(strUser,strDomain,strProfile,strScript, strHomedir)
Dim Computer
Dim User
Set Computer = Getobject("WinNT://" & strDomain)
Set User = computer.create("User",strUser)
Set objUser=objOU.Create("user", "cn=" & strUser)
objuser.put "givenName", strFullname
objuser.put "description", strDesc
objUser.put "homedrive", strHomeDrive
objUser.put "homeDirectory", strHomeDir
objUser.put "ScriptPath", strScript
objUser.put "ProfilePath", strProfile
objUser.SetInfo
call User.SetPassword(strPassword)

Set User = nothing
Set computer = nothing
End sub

running the script gives this error

error Object required: 'objOU'
code 800A01A8
source: Microsoft vbscript runtime error

im now wodering if i have taken on too bigger task !

thanks

Terry
 
Terry,

Sorry due to my last post you got something mixed up I think...

try this:
Code:
sub Adduserconfig(strUser,strDomain,strProfile,strScript, strHomedir)
Dim Computer
Dim User
Set Computer = Getobject("WinNT://" & strDomain)
[s]Set User = computer.create("User",strUser)[/s]
[highlight]Set objUser = computer.create("User","cn= " & strUser)[/highlight]
objuser.put "givenName", strFullname
objuser.put "description", strDesc
objUser.put "homedrive", strHomeDrive
objUser.put "homeDirectory", strHomeDir
objUser.put "ScriptPath", strScript
objUser.put "ProfilePath", strProfile
objUser.SetInfo
[highlight]objUser.SetPassword strPassword[/highlight]

Set User = nothing
Set computer = nothing
End sub

a little aside:
when you use parentheses to call a function the script asumes it will return a value. Therefore it needs to have a variable to put it in. ex: returncode = objUser.SetPassword (strPassword)
If you don't give a variable the script will quit on an error that you can ignore by using 'Call' ex: call objUser.SetPassword (strPassword)
Therefore if you remove the parentheses you can also remove 'call'

Hope you find this explanation usefull...

_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
as an aside apparently in strongly typed langs, vba for instance, the Call key word is used to specify that you must use the correct 'types' in your parameter list...i think
 
thanks for that i am going to have a play with it over the weekend to master this thing , i have got a temp solution that i will post when im at work just as it might help someone else it uses vbs input boxes and the chucks them into cmd and processes them. (works very well infact altho it is cheating some what )

many thanks
Terry
 
[tt]>Set Computer = Getobject("WinNT://" & strDomain)
>[blue]Set User = computer.create("User",strUser)[/blue]
>[red]Set objUser = computer.create("User","cn= " & strUser)[/red]
[/tt]
[1] Hello friends, we are on the wrong track.
[2] When you create user .create("User",strUser), (always) trap error. It is easy to create with abortion many times before properly created one. Hence, if you execute the same script more than one time, it will error out.
[3] To set user's login script and profile, you can use
[tt] objUser.loginscript="..."
objUser.profile="..."
objUser.setinfo
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top