Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding home directories to each user in script

Posted on 2006-07-24
3
Medium Priority
?
336 Views
Last Modified: 2008-02-07
Ok, looking for suggestions on ways to add the functionality of creating home directories to a script I have for creating users.  Here is the current script i have:


******************************************************************
' UserSpreadsheet .vbs
' Sample VBScript to create User accounts from a spreadsheet
' Author Guy Thomas http://computerperformance.co.uk/
' Version 4.6 - June 2005
' ------------------------------------------------------'
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet, i
Dim strCN, strSam, strFirst, strLast, strPWD, strDesc, StrDis

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'

strOU = "OU=Students, OU=AEC, OU=03 Schools," ' Note the comma
strSheet = "c:\creating users\aec\aectemp.xml"

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))

' 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 = ""
   strSam = Trim(objExcel.Cells(intRow, 1).Value)
   strCN = Trim(objExcel.Cells(intRow, 1).Value)
   strFirst = Trim(objExcel.Cells(intRow, 2).Value)
   strLast = Trim(objExcel.Cells(intRow, 3).Value)
   strPWD = Trim(objExcel.Cells(intRow, 4).Value)
   strDesc = Trim(objExcel.cells(intRow, 5).value)
   strDis = Trim(objExcel.cells(intRow, 6).value)

   ' Build the actual User from data in strSheet.
   Set objUser = objContainer.Create("User", "cn=" & strCN)
   objUser.sAMAccountName = strSam
   objUser.givenName = strFirst
   objUser.sn = strLast
   objUser.Put "DisplayName", strDis
   objUser.SetInfo

   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.ChangePassword "", strPWD
   objUser.SetInfo

intRow = intRow + 1
i = i + 1
Loop
objExcel.Quit


WScript.Echo "Finished Creating Users.  " & i & " Users created!"
WScript.Quit

' End of Sample UserSpreadsheet VBScript.
*****************************************************************

Thanks in advance.
0
Comment
Question by:matt1982
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 10

Assisted Solution

by:ryangorman
ryangorman earned 2000 total points
ID: 17174218
Add home directory path to column G and home drive letter to column H of the XML file

Change
   Dim strCN, strSam, strFirst, strLast, strPWD, strDesc, strDis
to
   Dim strCN, strSam, strFirst, strLast, strPWD, strDesc, strDis, strHomeDrive, strHomeDirectory

Add
   strHomeDirectory = Trim(objExcel.cells(intRow, 7).value)
   strHomeDrive = Trim(objExcel.cells(intRow, 8).value)
After
   strDis = Trim(objExcel.cells(intRow, 6).value)

Add
   objUser.homeDrive, strHomeDrive
   objUser.homeDirectory = strHomeDirectory
Before
   objUser.SetInfo
0
 
LVL 10

Accepted Solution

by:
ryangorman earned 2000 total points
ID: 17174287
The final piece is to have the script create the folder and set permissions as desired. You can easily adapt the following script that was written by the same author as your original script.

http://www.computerperformance.co.uk/vbscript/vbscript_cacls_excel.htm
0
 
LVL 10

Expert Comment

by:ryangorman
ID: 17193176
Thankyou
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question