Create User Script

Change Page: 12345 > | Showing page 1 of 5, messages 1 to 40 of 178
Author Message
cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Create User Script - Wednesday, June 08, 2005 8:59 PM
0
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")

crazymatt
  • Total Posts : 310
  • Scores: 0
  • Reward points : 0
  • Joined: 3/4/2005
  • Location:
Re: Create User Script - Wednesday, June 08, 2005 11:11 PM
0
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


cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 08, 2005 11:19 PM
0
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

royb5000
  • Total Posts : 54
  • Scores: 0
  • Reward points : 0
  • Joined: 5/4/2005
  • Location: USA
Re: Create User Script - Thursday, June 09, 2005 1:45 AM
0
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.

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 09, 2005 2:19 AM
0
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

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 09, 2005 2:51 AM
0
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

royb5000
  • Total Posts : 54
  • Scores: 0
  • Reward points : 0
  • Joined: 5/4/2005
  • Location: USA
Re: Create User Script - Thursday, June 09, 2005 5:25 AM
0
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.



nwcubsfan
  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 6/9/2005
  • Location: USA
Re: Create User Script - Thursday, June 09, 2005 5:54 AM
0
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.

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 09, 2005 9:33 PM
0
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

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Friday, June 10, 2005 5:02 AM
0
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")

royb5000
  • Total Posts : 54
  • Scores: 0
  • Reward points : 0
  • Joined: 5/4/2005
  • Location: USA
Re: Create User Script - Friday, June 10, 2005 5:55 AM
0
Couldn't you use the following?

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

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Sunday, June 12, 2005 4:44 AM
0
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

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 15, 2005 4:30 AM
0
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

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Wednesday, June 15, 2005 5:21 AM
0
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 on Tuesday, January 02, 2007 6:33 AM>

DragonMasterXX5
  • Total Posts : 52
  • Scores: 0
  • Reward points : 0
  • Joined: 6/13/2005
  • Location: USA
Re: Create User Script - Wednesday, June 15, 2005 9:09 AM
0
How could you make that so that it works in a webpage????????????

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Wednesday, June 15, 2005 9:46 AM
0
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 on Tuesday, January 02, 2007 6:33 AM>

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 15, 2005 11:47 PM
0
I like the look of your html script.

When i run it i get table does not exist?

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Thursday, June 16, 2005 3:45 AM
0
Does it give a line number?

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 16, 2005 4:29 AM
0
esnmb:

Hello mate, sorry forgot to put that in.

Yes its line 61

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Thursday, June 16, 2005 4:42 AM
0
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 on Tuesday, January 02, 2007 6:34 AM>

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 16, 2005 4:50 AM
0
esnmb:

I did indeed change it mate

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 16, 2005 7:25 PM
0
I am i missing something really simple here? i have been all over this scrit but cant quite get it to work

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Friday, June 17, 2005 2:22 AM
0
When do you get the error? Launching the file, clicking on Submit, Clear or Exit? I just copied the code and saved it as an HTA and everything worked for me...

jraisor
  • Total Posts : 39
  • Scores: 0
  • Reward points : 0
  • Joined: 4/29/2005
  • Location:
Re: Create User Script - Monday, June 27, 2005 2:04 AM
0
Does anyone know what i would need to do to this above mentioned script so it will write the following items as well from input boxes?

General Tab of account----
Description
Office
Phone number

Creating a Case for the Address tab so if a certain office is filled in it will aut populate the Street,City State and Zip

and finally

The organization tab:
Title
Dept
Comapany

and Manager.

If anyone has a script that is similar that has input boxes that includes this info or anyone that can help me out that would be great thanks.



cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Monday, June 27, 2005 11:10 PM
0
quote:
Originally posted by esnmb

When do you get the error? Launching the file, clicking on Submit, Clear or Exit? I just copied the code and saved it as an HTA and everything worked for me...



Hello mate, sorry its taken me so long to reply.

the error i get is

Line: 61

Char: 1

Error: Table does not exist

Code: 0

Any ideas as to what is going on?

I get this error when i click submit.

Cheers


esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Tuesday, June 28, 2005 7:55 AM
0
Take out this entire section and see if it works. This checks to see if the user name is in AD already before attempting to create the account:




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
<message edited by esnmb on Tuesday, January 02, 2007 6:34 AM>

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Tuesday, June 28, 2005 10:52 PM
0
That worked a treat. Thanks very much the script now runs through.

I have a small issue. I would like the user principalname to automatically put in the users username in before the @withers.net

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.Put "userPrincipalName", "@withers.net"
objUser.SetInfo


This is the whole code so far.

<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 = strFirst & ", " & strLast

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.Put "userPrincipalName", "@withers.net"
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 "Passw0rd"
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>

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Wednesday, June 29, 2005 1:56 AM
0
I believe you could just use this

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

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 29, 2005 5:04 AM
0
You are the man that worked a treat.

Thanks mate

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 29, 2005 5:09 AM
0
Ok my next issue is this. i have put "cn=" & strUser in to
("LDAP://"cn=" & strUser,OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

but when run it i get

Line: 93

Char: 15

Error: Expected ')'

I have put a ) all over the place trying to get it to work but it wont take it.

Any ideas as what i am doing wrong?

' Address Page Information

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

objUser.Put "streetAddress", "16 STREET ADDRESS"
objUser.Put "l", "London"
objUser.Put "postalCode", "POST CODE"
objUser.Put "c", "GB"
objUser.SetInfo


Many thanks for your help

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Wednesday, June 29, 2005 5:51 AM
0
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

Xandros
  • Total Posts : 100
  • Scores: 0
  • Reward points : 0
  • Joined: 6/23/2005
  • Location:
Re: Create User Script - Wednesday, June 29, 2005 8:32 AM
0
("LDAP://"cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

The problem is the double-quotes are unbalanced... remove the second one (immediately after the slashes).

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Wednesday, June 29, 2005 10:28 PM
0
Hello guys, thanks so much for both your help your comments worked a treat. The script is coming along very nice.

My next issue is i need to create a folder on a remote server and the folder needs to be based on the info in strUser

What i have so far is and i know its wrong:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\LNFS01\GWArchive\ & strUser")

Could you point me in the right direction of how i might do this. As you might have guessed i am new to vb and learning all the time.

Many thanks for your help so far.

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 30, 2005 12:28 AM
0
Its ok guys, i have worked it out

I have set it as follows

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\LNFS01\GWArchive\" & strUser & "")

Thanks to everyone who has helped so far i am sure i will be back with more questions

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 30, 2005 12:33 AM
0
Told you i would be back.

I have in my script

'This Section will Create The Users Home Drive on \\lnfs01\home$

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\LNFS01\home$\" & strUser & "")

So as you can see it is going to create the users home drive for me. Great. does anyone know how i can follow on from what i have got to give the user full NTFS permissions to this folder?

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Thursday, June 30, 2005 2:12 AM
0
There are two tools I've used. One from MS called SubInACL or a more powerful open source tool called SetACL.

Using SetACL, this will give the user Change access.

Set objShell = CreateObject("Wscript.Shell")

strDest = "\\LNFS01\home$\" & strUser
objShell.Run ("SetACL.exe -on """ & strDest & """ -ot file -actn ace " _
& "-ace ""n:YOURDOMAIN\" & strUser & ";p:change""")

Of course you can substitute "change" with "full".

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 30, 2005 2:28 AM
0
Thanks esnmb:

When i try to run this in my script i get an error:

Line: 162

Char: 1

Error: 'objscript'

I have downloaded setacl and copied it into the windows directory.

Any ideas why its failing?

Many thanks for all your help

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Thursday, June 30, 2005 2:31 AM
0
Look at mine again. I copied part of my code from another script. change objScript to objShell.

cjwallace
  • Total Posts : 549
  • Scores: 0
  • Reward points : 0
  • Joined: 3/5/2005
  • Location: United Kingdom
Re: Create User Script - Thursday, June 30, 2005 2:35 AM
0
Hi esnmb, sorry i must have copied your code before you had a chance to edit it.

Anyway i have changed the script and i now dont get the error but it has not put the user in the ntfs list

Any ideas? have i done something wrong. if you want i can post the whole script for you to look at

Thanks again for your continued help

esnmb
  • Total Posts : 453
  • Scores: 0
  • Reward points : 0
  • Joined: 1/11/2005
  • Location: USA
Re: Create User Script - Thursday, June 30, 2005 2:37 AM
0
Sure, post the whole thing so I can dig through it.

Does the user dir exist?

Change Page: 12345 > | Showing page 1 of 5, messages 1 to 40 of 178