Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Create User Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3296
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create User Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2 3 4 5   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Create User Script - 6/8/2005 7:59:24 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Guys. I have a vbscript that will create a user in AD and fill out all the fields that i want it to, set a password, create a folder etc etc.

Now the script works really well apart from one part. To create a user i would have to go into the script and change all the imformation like Name, Display Name, Initals, Ext number, email address, etc etc

What i am trying to achive, is when the vbscript is run, it will open up a box that i can enter Name, Initals, Ext number and it will go through my script changing all the parts it needs to, then it will create the user.

Can anyone help me on this?

Many thanks to anyone in advance


My Script

' This Section Will create the Active Directory User Account

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

Set objUser = objOU.Create("User", "cn=Craig Wallace")
objUser.Put "sAMAccountName", "cxw"
objUser.Put "userPrincipalName", "cxw@withers.net"
objUser.SetInfo

' This Section will assign the user a standard password

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.SetPassword "Passw0rd"

' This Section will force the user to change their password at next login

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "pwdLastSet", 0
objUser.SetInfo

' This Section will enable the users Active Directory Account

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.AccountDisabled = False
objUser.SetInfo

' General Page Information

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "givenName", "Craig"
rem objUser.Put "initials", "E."
objUser.Put "sn", "Wallace"
objUser.Put "displayName", "Craig Wallace"
objUser.Put "physicalDeliveryOfficeName", "London"
rem objUser.Put "telephoneNumber", ""
objUser.Put "mail", "Craig.Wallace@withersworldwide.com"
objUser.Put "wWWHomePage", "http://www.withersworldwide.com"
objUser.SetInfo


' Address Page Information

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "streetAddress", "16 Old Bailey"
objUser.Put "l", "London"
objUser.Put "postalCode", "EC4M 7EG"
objUser.Put "c", "GB"
objUser.SetInfo

' Users Home & Profile Information

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "profilePath", "\\LNFS01\Profiles$\cxw"
objUser.Put "homeDirectory", "\\LNFS01\Home$\cxw"
objUser.Put "homeDrive", "H"
objUser.SetInfo

' Users Telephone Information

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "facsimileTelephoneNumber", "+44 (0)20 7597 6543"
objUser.SetInfo

' Organization Information

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "department", "Family Department"
objUser.Put "company", "Withers LLP"
objUser.SetInfo

'This Section Will Add the user to the standard Security Groups

Const ADS_PROPERTY_APPEND = 3

Set objGroup = GetObject _
("LDAP://cn=LN London Users,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

Set objGroup = GetObject _
("LDAP://cn=LN Family,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

Set objGroup = GetObject _
("LDAP://cn=LN GWArchive,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

'This Section will Create The Groupwise Archive Folder on \\LNFS01\GWArchive$\%username%

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\LNFS01\GWArchive\cxw")
 
 
Post #: 1
 
 Re: Create User Script - 6/8/2005 10:11:13 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
I guess this can be done in two ways (or more ;p),

1: create a HTA page where you fill in all this stuff
(this might be the best way and easiest way)

2: Create a msgbox where you can put all the info in, seperate the info with "," and then read the string into an array by using split with "," as a delimiter. This might not work if there are info missing. Alt. create one msgbox for each inputtype, lots of boxes though.

Hope this helps.

/Matt

(in reply to cjwallace)
 
 
Post #: 2
 
 Re: Create User Script - 6/8/2005 10:19:11 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
crazymatt. Many thanks for the reply.

Sorry to be a pain but i am still very new to vbscript. could you give me some examples of both using something from my code above?

Many thanks

(in reply to cjwallace)
 
 
Post #: 3
 
 Re: Create User Script - 6/9/2005 12:45:24 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Couldn't you use the script that i have in the following topic to do what you want? http://www.visualbasicscript.com/topic.asp?TOPIC_ID=3270 I think you could probably modify it to include all of the fields that you are inserting manually with the script that you used for an example. You would just need to move them out of whatever ou that you create them in from the script to the one that they belong to. Hope this is some help.

(in reply to cjwallace)
 
 
Post #: 4
 
 Re: Create User Script - 6/9/2005 1:19:36 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
I could but, i would really like to use the script from above as i know every field works and works really well.

I like the look of yours, could you or anyone else help me with what i am trying to achive.?

Many thanks for your help so far

(in reply to cjwallace)
 
 
Post #: 5
 
 Re: Create User Script - 6/9/2005 1:51:09 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
What i would like to have, is a msgbox open up that will let me enter The Users Name, their username, Initals, and change the rest of the script

(in reply to cjwallace)
 
 
Post #: 6
 
 Re: Create User Script - 6/9/2005 4:25:14 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Could you use something like this?

objUserinput = InputBox("Please enter user's name:")

Set objUser = objOU.Create("User", "cn=" & objUserinput)

You would just have to create and input box and a input result variable for each field. Sorry if this isn't helping, I am an amatuer at this myself.

(in reply to cjwallace)
 
 
Post #: 7
 
 Re: Create User Script - 6/9/2005 4:54:40 AM   
  nwcubsfan

 

Posts: 10
Score: 0
Joined: 6/9/2005
From: USA
Status: offline
I did this very thing myself. I created an .hta file for use by our HR department. They fill out the first name, the last name, the description, office location, etc. The .hta writes these values to a text file. Next, a sceduled task runs with a priveleged account to read the textfile, mine out the data, and then runs the script with the parameters it got from the textfile. This works great because non-admins can fill out the form, and all they need is write access to the folder that the .hta file wants to send the results file to.

Now, to answer your question, just create an InputBox for your variables.

Example...

strUsername = InputBox("Enter the username","Username")

This sets strUsername to whatever you put in the box.

By the way, if you are using Windows Server 2003, I would reccommend using the DSADD command to create users rather than just stuffing values into the Active Directory. I do this and it works great.

(in reply to cjwallace)
 
 
Post #: 8
 
 Re: Create User Script - 6/9/2005 8:33:31 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
quote:
Originally posted by royb5000

Could you use something like this?

objUserinput = InputBox("Please enter user's name:")

Set objUser = objOU.Create("User", "cn=" & objUserinput)

You would just have to create and input box and a input result variable for each field. Sorry if this isn't helping, I am an amatuer at this myself.






Thanks mate for your input you have put me on the right track :-)

I am going to work through this script bit by bit until i get it right \ working.

Ok now i have done what you suggested and it has worked for Users Name and Initals , Now i would like objUser.Put "userPrincipalName", "cxw@withers.net" to pick up the initals that was entered earlier in the script.

How would i achive this?

Thanks to anyone in advance

(in reply to cjwallace)
 
 
Post #: 9
 
 Re: Create User Script - 6/10/2005 4:02:13 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Not to worry i have solved the issue. It was

objUser.Put "userPrincipalName", objUserinput & "@withers.net"

My next issue in the script is this:

I would like

("LDAP://cn=Craig Wallace, to populate from

objUserinput = InputBox("Please enter user's name:")
Set objUser = objOU.Create("User", "cn=" & objUserinput)

How could i achive this?

The script so far is:

Option Explicit
Dim WshShell, fso
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")


' This Section Will create the Active Directory User Account

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUserinput = InputBox("Please enter user's name:")
Set objUser = objOU.Create("User", "cn=" & objUserinput)

objUserinput = InputBox("Please enter user's Initials:")
objUser.Put "sAMAccountName", objUserinput

objUser.Put "userPrincipalName", objUserinput & "@withers.net"
objUser.SetInfo

' This Section will assign the user a standard password

Set objUser = GetObject _
("LDAP://cn=Craig Wallace,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

(in reply to cjwallace)
 
 
Post #: 10
 
 Re: Create User Script - 6/10/2005 4:55:18 AM   
  royb5000

 

Posts: 54
Score: 0
Joined: 5/4/2005
From: USA
Status: offline
Couldn't you use the following?

Set objUser = GetObject _
("LDAP://cn=" & objUserInput & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

(in reply to cjwallace)
 
 
Post #: 11
 
 Re: Create User Script - 6/12/2005 3:44:28 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate, thanks for the reply.

I will give it a go when i get into the office on monday.

Will let you know how it goes

Cheers

(in reply to cjwallace)
 
 
Post #: 12
 
 Re: Create User Script - 6/15/2005 3:30:31 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello guys. Sorry its taken me so long to reply been really busy with AD

I have tried

"Couldn't you use the following?"

Set objUser = GetObject _
("LDAP://cn=" & objUserInput & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

But when i run it, it tells me no such object.

Does Anyone else have ideas on how i might achive this?

Thanks in advance

(in reply to cjwallace)
 
 
Post #: 13
 
 Re: Create User Script - 6/15/2005 4:21:37 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
This will prompt as well as check for the existance of the user before creating...



Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

strUser = InputBox("Enter Acount name", "Account Creation")
If strUser = "" Then
MsgBox "You're missing required fields",64, "Alert"
Wscript.quit
End If

strFirst = InputBox("Enter First name", "Account Creation")
If strFirst = "" Then
MsgBox "You're missing required fields",64, "Alert"
Wscript.quit
End If

strInitial = InputBox("Enter Initial", "Account Creation")

strLast = InputBox("Enter Last name", "Account Creation")
If strLast = "" Then
MsgBox "You're missing required fields",64, "Alert"
Wscript.quit
End If

strDisplay = strLast & ", " & strFirst

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<GC://dc=DOMAIN,dc=com>;(&(objectCategory=Person)(objectClass=user)" & _
"(samAccountName=" & strUser & "));samAccountName;subtree"

Set objRecordSet = objCommand.Execute

If objRecordSet.RecordCount = 0 Then
Else
MsgBox "The User Account already exists.",48,"Alert"
Wscript.Quit
End If

objConnection.Close

Set objOU = GetObject("LDAP://OU=Test Users,OU=Test All Users,OU=Testing OU,DC=DOMAIN,DC=com")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.SetInfo

objUser.Put "givenName", strFirst

If strInitial = "" Then
Else
objUser.Put "initials", strInitial
End If

objUser.Put "sn", strLast
objUser.Put "displayName", strDisplay

objUser.SetPassword "password"
objUser.Put "pwdLastSet", 0

intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
objUser.SetInfo
End If

< Message edited by esnmb -- 1/2/2007 5:33:23 AM >

(in reply to cjwallace)
 
 
Post #: 14
 
 Re: Create User Script - 6/15/2005 8:09:21 AM   
  DragonMasterXX5

 

Posts: 52
Score: 0
Joined: 6/13/2005
From: USA
Status: offline
How could you make that so that it works in a webpage????????????

(in reply to cjwallace)
 
 
Post #: 15
 
 Re: Create User Script - 6/15/2005 8:46:44 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
This is from my HTA. I can't get it to work in an HTML page with the GetObject. I have a page that works, but I call an external script that does the actual user creation. Copy this code and name the extension to hta to make is a stand alone app, or HTML and see if it works for you...

'===============================


<html>
<HTA:APPLICATION
APPLICATIONNAME="Account Creation"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<head>
<title>User Account Creation Form</title>
<style type="text/css">
<!--
.style3 {font-size: 13px}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
.style2 { font-family: Arial, Helvetica, sans-serif;
font-size: 13.5pt;
color: #CC6600;
font-weight: bold;
}
.style5 {font-size: small; color: #FF0000; }
.style6 {color: #FF0000}
-->
</style>

<script type="text/vbscript">
Sub CreateAccount

strUser = TextBox0.Value
If strUser = "" Then
MsgBox "You're missing required fields.",64, "Alert"
Exit Sub
End If

strFirst = TextBox1.Value
If strFirst = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strInitial = TextBox2.Value

strLast = TextBox3.Value
If strLast = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strDisplay = strLast & ", " & strFirst

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<GC://dc=DOMAIN,dc=com>;(&(objectCategory=Person)(objectClass=user)" & _
"(samAccountName=" & strUser & "));samAccountName;subtree"

Set objRecordSet = objCommand.Execute

If objRecordSet.RecordCount = 0 Then

Else
MsgBox "The User Account already exists.",48,"Alert"
Exit Sub
End If

objConnection.Close

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

Set objOU = GetObject("LDAP://OU=Test Users,OU=Test All Users,OU=Testing OU,DC=fabrikam,DC=com")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.SetInfo

objUser.Put "givenName", strFirst

If strInitial <> "" Then
objUser.Put "initials", strInitial
End If

objUser.Put "sn", strLast
objUser.Put "displayName", strDisplay

objUser.SetPassword "password"
objUser.Put "pwdLastSet", 0

intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
End If
objUser.SetInfo

End Sub

Sub Reload
Location.Reload(True)
End Sub

Sub bodyLoaded()
window.ResizeTo 600,510 ' WIDTH, HEIGHT
End Sub

</script>
</head>
<body onLoad="bodyLoaded()">
<p><img src="/images/logo.gif" width="189" height="46"></p>
<p class="style2">Account Creation Page.</p>
<table width="289" border="0" align="left">
<tr>
<td width="89"><span class="style5">*</span>Login ID: </td>
<td width="144"><input type="text" name="textbox0"></td>
</tr>
<tr>
<td><span class="style5">*</span>First Name:</td>
<td><input type="text" name="textbox1"></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="textbox2"></td>
</tr>
<tr>
<td><span class="style5">*</span>Last Name: </td>
<td><input type="text" name="textbox3"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p><br>
<input type="button" name="Submit" value="Submit" onClick="CreateAccount">
</p>
<p>The login ID will have an initial password of password. </p>
<p>The new employee will also be requiered to change their password at first logon. </p>
<p class="style3"><span class="style6">*</span> Indicates Required Field</p>
<p>
<input id="reloadbutton" class="button" type="reset" value="Clear Form" name="reload_button" onClick="Reload">
</p>
<p>
<input type="button" value=" Exit " name="close_button" onClick="Self.Close">
</p>
</body>
</html>

< Message edited by esnmb -- 1/2/2007 5:33:58 AM >

(in reply to cjwallace)
 
 
Post #: 16
 
 Re: Create User Script - 6/15/2005 10:47:33 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
I like the look of your html script.

When i run it i get table does not exist?

(in reply to cjwallace)
 
 
Post #: 17
 
 Re: Create User Script - 6/16/2005 2:45:00 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Does it give a line number?

(in reply to cjwallace)
 
 
Post #: 18
 
 Re: Create User Script - 6/16/2005 3:29:55 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
esnmb:

Hello mate, sorry forgot to put that in.

Yes its line 61

(in reply to cjwallace)
 
 
Post #: 19
 
 Re: Create User Script - 6/16/2005 3:42:23 AM   
  esnmb

 

Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Did you update this with your Domain name: <GC://dc=FABRIKAM,dc=COM> ?

objCommand.CommandText = _
"<GC://dc=DOMAIN,dc=com>;(&(objectCategory=Person)(objectClass=user)" & _
"(samAccountName=" & strUser & "));samAccountName;subtree"

< Message edited by esnmb -- 1/2/2007 5:34:17 AM >

(in reply to cjwallace)
 
 
Post #: 20
 
 
Page:   [1] 2 3 4 5   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create User Script Page: [1] 2 3 4 5   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts