Computing.Net > Forums > Programming > VBScript: Create new OU or new User

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBScript: Create new OU or new User

Reply to Message Icon

Name: Lithium (by Minki)
Date: June 11, 2007 at 22:34:09 Pacific
OS: Microsoft Windows 98/XP
CPU/Ram: 350 MHz / 64 MB SDRAM
Product: Compaq Presario 1670
Comment:

I've wrote the below script and most of it is functioning properly:
---------------------

'VBScript
sub createou(x) 'Defining VBScript procedure
set dom = Getobject("LDAP://dc=swantafe,dc=edu,dc=au") 'Connecting to database
a= "OU=" & x
set ouExecutive = dom.create("organizationalunit", a) 'Creating the object (OU)
ouExecutive.setinfo
End sub

sub createuser(x)
set objou = Getobject("LDAP://ou=IT,dc=swantafe,dc=edu,dc=au")
a = "cn=" & x
set objusr = objou.create("User", c)
objuser.setinfo
end sub

'Create main menu
do while y <> "q"
y = inputbox("Main menu" & VBcrlf & "1: Create user." & VBcrlf & "2: Create organisational unit." & VBcrlf & "q: Quit.")

Select case y
Case "1"
z = inputbox("Enter username.")
createuser(z)
Case "2"
z = inputbox("Enter Organisational unit name.")
end select
loop

However, everytime I try to create a user using it, it comes up with the following error:

Script: E:\folder\vbs\Create new OU or new user.vbs
Line: 12
Character: 1
Error: One or more input parameters are invalid.

Code: 80005008
Source: Active Directory

Could someone tell me what I've done wrong?

Life is but a dream ...



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: June 12, 2007 at 00:56:47 Pacific
Reply:

I'm assuming it's this line:
set objusr = objou.create("User", c)

Question: Where is 'c' set? I don't see it.
Hint: When working with VBScript, make the very first line of code:
Option Explicit
It'll force you to declare your variables, which in tern saves you from a world of frustration.


0

Response Number 2
Name: Lithium (by Minki)
Date: June 12, 2007 at 19:29:21 Pacific
Reply:

Yes, the 'c' didn't belong there so I changed it. But I also found quite a few other errors on there that I've now sorted out. Thanks for your help!

Life is but a dream ...


0

Response Number 3
Name: tonysathre
Date: June 13, 2007 at 16:13:04 Pacific
Reply:

'Create a new user:

Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")

Set objUser = objOU.Create("User", "cn=MyerKen")
objUser.Put "sAMAccountName", "myerken"
objUser.SetInfo

'Create a new OU:

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")

Set objOU = objDomain.Create("organizationalUnit", "ou=Management")
objOU.SetInfo


"Computer security." — Oxymoron


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBScript: Create new OU or new User

Create new dir based on dir names www.computing.net/answers/programming/create-new-dir-based-on-dir-names/19742.html

VBS adding local users to computers www.computing.net/answers/programming/vbs-adding-local-users-to-computers/15319.html

Create text file based on user input www.computing.net/answers/programming/create-text-file-based-on-user-input/20212.html