| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 79095 | 2007-05-08 01:41:00 | help with create users vbscript | Greven (91) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 548158 | 2007-05-08 01:41:00 | When I run my create users script, i get an error I can ' t work out: Attached file: script_error.JPG (www.imagef1.net.nz) (13 KB) it even comes up when I don ' t set any properties. the script is: Dim dse, domain, ou function userExists(sUsername) Dim oUser, oDomain userExists=false ' Connect to the appropriate domain and collect all the ' user accounts in it. Set oDomain = GetObject( " WinNT://stjohns.local " ) oDomain.Filter = Array( " user " ) ' Examine each user account to determine whether the name in ' the argument matches the name associated with the account. For Each oUser In oDomain If LCase(oUser.Name) = LCase(sUserName) Then WScript.Echo oUser.Name & " already has an account. " userExists=true End If Next End function Dim objRootLDAP, objContainer, objUser, objShell Dim objExcel, objSpread, intRow Dim strUser, strOU, strSheet, strGroup Dim strCName, strUserName, strFirst, strLast, strPWD Dim fso, fldUserHomedir, wshShell Dim strGroup2, strUser2, strDNSDomain Dim objGroup, usr Dim strTest, strPath, ouName strSheet = " C:\scripts\users.xls " ouName= " Restricted " ' Set objRootLDAP = GetObject( " LDAP://rootDSE " ) ' Set objContainer = GetObject( " LDAP:// " & objRootLDAP.Get( " defaultNamingContext " )) set dse = GetObject( " LDAP://RootDSE " ) set domain = GetObject( " LDAP:// " & dse.Get( " defaultNamingContext " )) set ou = domain.GetObject( " organizationalUnit " , " OU=restricted " ) ' Open the Excel spreadsheet Set objExcel = CreateObject( " Excel.Application " ) Set objSpread = objExcel.Workbooks.Open(strSheet) intRow = 3 ' Row 1 often contains headings ' Here is the ' DO...Loop ' that cycles through the cells ' Note intRow, x must correspond to the column in strSheet Do Until objExcel.Cells(intRow,1).Value = " " strUserName = Trim(objExcel.Cells(intRow, 1).Value) strCName = Trim(objExcel.Cells(intRow, 2).Value) strFirst = Trim(objExcel.Cells(intRow, 3).Value) strLast = Trim(objExcel.Cells(intRow, 4).Value) strPWD = Trim(objExcel.Cells(intRow, 5).Value) strGroup = Trim(objExcel.Cells(intRow, 6).Value) If userExists(strUserName)=false Then strPath = " \\server\users$\ " & strUserName wscript.echo " Creating user in " & ou.Name set usr = ou.Create( " user " , " cn= " & strUserName ) ' usr.Put " samAccountName " , strUserName ' usr.Put " userPrincipalName " , strUserName ' usr.Put " Profilepath " , strPath ' usr.Put " givenName " , strFirst ' usr.Put " sn " , strLast usr.SetInfo wscript.echo " User " & strUserName & " was created successfully in " & ou.Name & " with a RUP " End If intRow = intRow + 1 Loop objExcel.Quit WScript.Quit |
Greven (91) | ||
| 1 | |||||