Login | |
|
 |
Re: Create User Script - 6/30/2005 1:40:06 AM
|
|
 |
|
| |
cjwallace
Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
|
Hello mate, thanks for taking the time to look at it. Look for 'This Section will Create The Users Home Drive on \\lnfs01\home$ It should have created the home drive before it runs the script you have just posted. I may be missing something The Script 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 ' This section will create the user & set part of the General Page. 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", strUser & "@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 ' This section will assign the user a standard password 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 ' 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 Old Bailey" objUser.Put "l", "London" objUser.Put "postalCode", "EC4M 7EG" objUser.Put "c", "GB" objUser.SetInfo ' General Page Information Set objUser = GetObject _ ("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net") objUser.Put "physicalDeliveryOfficeName", "London" objUser.Put "telephoneNumber", "+44 (0)20 7597" objUser.Put "mail", "@withersworldwide.com" objUser.Put "wWWHomePage", "http://www.withersworldwide.com" objUser.SetInfo ' Users Telephone Information Set objUser = GetObject _ ("LDAP://cn=" & strUser & ",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=" & strUser & ",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=" & strUser & ",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=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net") objGroup.SetInfo
|
|
| |
|
|
|
 |
Re: Create User Script - 6/30/2005 1:56:48 AM
|
|
 |
|
| |
esnmb
Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
|
I removed some quotes from places like when you create the dir after the username. It may not matter, but I took that section of code and modified it so I can create a dir and ACL it on one of my shares and it worked. <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 ' This section will create the user & set part of the General Page. 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", strUser & "@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 ' This section will assign the user a standard password 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 ' 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 Old Bailey" objUser.Put "l", "London" objUser.Put "postalCode", "EC4M 7EG" objUser.Put "c", "GB" objUser.SetInfo ' General Page Information Set objUser = GetObject _ ("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net") objUser.Put "physicalDeliveryOfficeName", "London" objUser.Put "telephoneNumber", "+44 (0)20 7597" objUser.Put "mail", "@withersworldwide.com" objUser.Put "wWWHomePage", "http://www.withersworldwide.com" objUser.SetInfo ' Users Telephone Information Set objUser = GetObject _ ("LDAP://cn=" & strUser & ",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=" & strUser & ",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=" & strUser & ",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=" & strUser & ",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=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net") objGroup.SetInfo ' Users Home & Profile Information Set objUser = GetObject _ ("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
|
|
| |
|
|
|
 |
Re: Create User Script - 6/30/2005 6:05:13 AM
|
|
 |
|
| |
Bezerk
Posts: 22
Score: 0
Joined: 6/20/2005
From: Netherlands
Status: offline
|
Hi, I have a script that i am currently working on that work very well, easy to customize. I have seen an example on www.computerperformance.co.uk and toke that as my [code] SECTION A DECLARE VARIABLES Option Explicit ' Objects declared : Dim objRootDSE, objFSO, objShell Dim objUser, objGroup, objContainer Dim objExcel, objSheet Dim objExcelFile ' Strings declared : Dim strCN, strNTSam, strPWD, strOUContainer, strUPN, strEnable Dim strGroupDN, strLast, strFirst, strDescription, strGroup Dim strHomeFolder, strHomeDrive Dim strNetBIOSDomain, strDomain ' Integers declared : Dim intNumusers, intRunError, intRow, intCol 'Declare Constants: objExcelFile = "C:\scripts\addusers.xls" strPWD = "Welkom01" 'SECTION B CONNECT TO ACTIVE DIRECTORY ' Get Domain name from RootDSE object. Set objRootDSE = GetObject("LDAP://RootDSE") strDomain = objRootDSE.Get("DefaultNamingContext") 'Section C OPEN AND READ THE SPREADSHEET ' Connect to spreadsheet where users are stored Set objExcel = CreateObject("Excel.Application") ' Open the Speadsheet (Error Handling Section). On Error Resume Next Err.Clear objExcel.Workbooks.Open objExcelFile If Err.Number <> 0 Then Err.Clear On Error GoTo 0 Wscript.Echo "Kan de file niet vinden!" & Space(2) & objExcelFile Wscript.Quit End If On Error GoTo 0 Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) ' SECTION F DO LOOP UNTIL EMPTY CELL IN SPREADSHEET 'start at row 2 first row is for headlines intRow = 2 Do ' Read values from spreadsheet for this user. strCN = Trim(objSheet.Cells(intRow, 1).Value) strNTSam = Trim(objSheet.Cells(intRow, 2).Value) strOUContainer = Trim(objSheet.Cells(intRow, 3).Value) strFirst = Trim(objSheet.Cells(intRow, 4).Value) strLast = Trim(objSheet.Cells(intRow, 5).Value) strUPN = Trim(objSheet.Cells(intRow, 6).Value) strHomeFolder = Trim(objSheet.Cells(intRow, 7).Value) strHomeDrive = Trim(objSheet.Cells(intRow, 8).Value) strEnable = Trim(objSheet.Cells(intRow, 9).Value) strDescription = Trim(objSheet.Cells(intRow, 10).Value) strGroup = Trim(objSheet.Cells(intRow, 12).Value) 'extra section for error handling ' Connect to OU where users to be created. On Error Resume Next Err.Clear Set objContainer = GetObject("LDAP://" & strOUContainer) If Err.Number <> 0 Then Err.Clear On Error GoTo 0 Wscript.Echo "Edit the LDAP path to your OU " & strOUContainer Wscript.Quit End If On Error GoTo 0 'SECTION D CREATE THE USER On Error Resume Next Err.Clear Set objUser = objContainer.Create("user", "cn=" & strCN) If Err.Number <> 0 Then Err.Clear On Error GoTo 0 Wscript.Echo "Cannot create user with cn: " & strCN Else On Error GoTo 0 ' Assign mandatory attributes cn and sAMAccountName. If strNTSam = "" Then strNTSam = strCN End If objUser.sAMAccountName = strNTSam On Error Resume Next Err.Clear objUser.SetInfo If Err.Number <> 0 Then Err.Clear On Error GoTo 0 Wscript.Echo "Unable to create user with NT SAM name: " & strNTSam Else ' Set password for user. objUser.SetPassword strPWD If Err.Number <> 0 Then Err.Clear On Error GoTo 0 Wscript.Echo "Unable to set password for user " & strNTSam End If On Error GoTo 0 ' Enable the user account. objUser.AccountDisabled = False If strFirst <> "" Then objUser.givenName = strFirst End If ' Assign values to remaining attributes. If strLast <> "" Then objUser.sn = strLast End If If strUPN <> "" Then
|
|
| |
|
|
|
|
|