Login | |
|
 |
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")
|
|
| |
|
|
|
 |
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.
|
|
| |
|
|
|
 |
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")
|
|
| |
|
|
|
 |
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 >
|
|
| |
|
|
|
 |
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 >
|
|
| |
|
|
|
|
|