Help with addusers script and profile path

Overview:
Add 600 students as users to the domain. The students user accounts must be associated with a home folder and profile path. To enter all these users in by hand would take days in which I do not have to spend on this task.

System:
Windows 2003 Standard SP1


Question:

I need to add 600 users to Win2k3 AD. I have been searching experts-exchange posts for help with an addusers script. I have found a script that 4auHuk wrote over in the Windows 2000 section that pulls a full name from a .txt file and then creates the users in the "users" container in AD. The script is pasted below. This script is what I was looking for with the exception that their is no profile path included for the imported users (as far as I can tell). My question is how can this script be edited to add the profile path for each user and create a "homefolder" for their profiles? I have very little scripting knowledge and I am offering 500 points to anyone that can assist me with this much needed help. Will this script even work with Win2k3?

Thanks in advance.

The script (by 4auHuk): http://www.experts-exchange.com/Operating_Systems/Win2000/Q_20896223.html

----start----

On Error Resume Next
dcroot = "dc=company,dc=org"   ' Base path. Put "dc=subdomain,dc=domain,dc=domain" here.
Password = "password"              ' Default password assigned to all created users
usrfile = "c:\users.txt"                 ' File containing users' full names list.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(usrfile) Then
    Set objFile = objFSO.OpenTextFile(usrfile, 1)
Else
    Wscript.Echo "File" & usrfile & " does not exist."
    WScript.Quit
End If

WScript.Echo "Reading user names from " & usrfile & VbCrLf
WScript.Echo "Line number:" & VbTab & "Action:"
WScript.Echo "=================================================="
Do Until objFile.AtEndOfStream
    succ = FALSE
    i = 1
    CurLine = objFile.Line
    Fullname = objFile.ReadLine
    If not FullName = "" Then
        st = InStr(FullName, " ")
        FirstName = Mid(FullName,1,st-1)
        LastName  = Mid(FullName,st+1)
        LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,1))
        Set objContainer = GetObject("LDAP://cn=Users," & dcroot)
        If Err <> 0 Then
            WScript.Echo "Can not bind to " & dcroot & ". Check syntax."
            WScript.Quit
        End If
        Err.Clear
        Do Until succ or i>3
            Set objNew = objContainer.Create("User", "cn=" & FullName)
            objNew.Put "sAMAccountName", LogonName
            objNew.SetInfo
            If Err <> 0 Then
                 i = i+1
                LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,i))
                Err.Clear
            Else
                succ = TRUE
                objNew.Put "givenName", FirstName
                objNew.Put "sn", LastName
                objNew.Put "displayName", FirstName & " " & LastName
                objNew.SetInfo
                Set objNew = Nothing
                Set objUser = GetObject("LDAP://cn=" & _
                              FullName & ",cn=Users," & dcroot)
                objUser.ChangePassword "", Password
                objUser.SetInfo
                If Err <> 0 Then
                    pwderr = "Can not set password (restrictions?). Left blank."
                    Err.Clear
                Else
                    pwderr = ""
                End If
                objUser.AccountDisabled = FALSE
                objUser.Put "pwdLastSet", 0
                objUser.SetInfo
                Set objUser = Nothing
                WScript.Echo CurLine & vbTab & vbTab & "User """ & _
                             FullName & """ (" & LogonName & ") created. " & pwderr
            End If
        Loop
        If not succ Then
            WScript.Echo CurLine & vbTab & vbTab & _
                         "Can not create user """ & FullName & """"
        End If
    Else
        WScript.Echo CurLine & vbTab & vbTab & _
                     "Skipping Empty line in " & usrfile
    End If
Loop
objFile.Close

----end-----
Terr0rAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mass2612Connect With a Mentor Commented:
Hi again,

How long can I make this thread ;-) I think this version works better as you can specify alternate OU's to create the accounts in and can modify the variables without needing to mess around in the code. The original script specifies CN=Users which you would need to change to OU=orgUnitName if you wanted to change it.

Start script *******************************************
On Error Resume Next
dcroot = "dc=test,dc=org"   ' Base path. Put "dc=subdomain,dc=domain,dc=domain" here.
ou = "OU=Test,"                 ' specifies the OU where the account should be created
Password = "password"              ' Default password assigned to all created users
usrfile = "c:\users.txt"                 ' File containing users' full names list.
homedrv = "H"                        ' specifices the letter to use for home drive
homeshare = "\\server01\home"      ' specifies the server and share for home folders
logscript = "logon.bat"                  ' specifies the logon script name

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(usrfile) Then
    Set objFile = objFSO.OpenTextFile(usrfile, 1)
Else
    Wscript.Echo "File" & usrfile & " does not exist."
    WScript.Quit
End If

WScript.Echo "Reading user names from " & usrfile & VbCrLf
WScript.Echo "Line number:" & VbTab & "Action:"
WScript.Echo "=================================================="
Do Until objFile.AtEndOfStream
    succ = FALSE
    i = 1
    CurLine = objFile.Line
    Fullname = objFile.ReadLine
    If not FullName = "" Then
        st = InStr(FullName, " ")
        FirstName = Mid(FullName,1,st-1)
        LastName  = Mid(FullName,st+1)
        LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,1))
        Set objContainer = GetObject("LDAP://" & ou & dcroot)
        If Err <> 0 Then
            WScript.Echo "Can not bind to " & ou & dcroot & ". Check syntax."
            WScript.Quit
        End If
        Err.Clear
        Do Until succ or i>3
            Set objNew = objContainer.Create("User", "cn=" & FullName)
            objNew.Put "sAMAccountName", LogonName
            objNew.SetInfo
            If Err <> 0 Then
                 i = i+1
                LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,i))
                Err.Clear
            Else
                succ = TRUE
                objNew.Put "givenName", FirstName
                objNew.Put "sn", LastName
                objNew.Put "displayName", FirstName & " " & LastName
                objNew.SetInfo
                Set objNew = Nothing
                Set objUser = GetObject("LDAP://cn=" & _
                              FullName & "," & ou & dcroot)
                objUser.ChangePassword "", Password
                objUser.SetInfo
                If Err <> 0 Then
                    pwderr = "Can not set password (restrictions?). Left blank."
                    Err.Clear
                Else
                    pwderr = ""
                End If
                objUser.AccountDisabled = FALSE
                objUser.Put "pwdLastSet", 0
                objUser.Put "homeDirectory", homeshare & "\" & LogonName
                       objUser.Put "homeDrive", homedrv
                       objUser.Put "scriptPath", logscript
                       objUser.SetInfo
     Set objUser = Nothing
                WScript.Echo CurLine & vbTab & vbTab & "User """ & _
                             FullName & """ (" & LogonName & ") created. " & pwderr
            End If
        Loop
        If not succ Then
            WScript.Echo CurLine & vbTab & vbTab & _
                         "Can not create user """ & FullName & """"
        End If
    Else
        WScript.Echo CurLine & vbTab & vbTab & _
                     "Skipping Empty line in " & usrfile
    End If
Loop
objFile.Close

End script **********************************************************
0
 
mass2612Commented:
Hi,

I've not tested this as I don't have access to my test environment but try adding below the objUser.Put "pwdLastSet", 0 line.

objUser.Put "homeDirectory", "\\servername\" & LogonName
objUser.Put "homeDrive", "H"

where H = drive letter you want to assign
0
 
mass2612Commented:
Try this for the profile path. Again place this under the home directory lines. I would do this one at a time and test.

obUser.Put "profilePath", "\\servername\" & LogonName

Let us know how you get on.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Terr0rAuthor Commented:
Thanks for your input mass2612. It is late, and I have been gone all day, but will VPN in tomorrow afternoon to test this with a few users and let you know how it goes.
0
 
Terr0rAuthor Commented:
>> objUser.Put "homeDirectory", "\\servername\" & LogonName
      objUser.Put "homeDrive", "H"

I am assuming that I would use the entire path to the homedirectory share correct?

example: \\servername\share\home\

Also, objUser.Put "homeDrive", "H" maps this drive for the user? Just want to make sure exactly what this does before I test it. I am not a scripter, but I am assuming this is what the code is doing?

Thanks again for your input.
0
 
mass2612Commented:
Yeah you need to add the correct share path that you wish to use. H: would be the letter you want the users to see.

I'll be able to test this tomorrow.
0
 
Terr0rAuthor Commented:
I ran the script on a text file with 4 users full names. I also edited the script here:

dcroot = "dc=company,dc=org"   ' Base path. Put "dc=subdomain,dc=domain,dc=domain" here.
Password = "password"              ' Default password assigned to all created users
usrfile = "c:\users.txt"                 ' File containing users' full names list.

The script output below:


C:\>cscript /nologo makeuser.vbs
Reading user names from c:\users.txt

Line number:    Action:
==================================================
1               User "John Doe" (doej) created.
Can not bind to dc=malden,dc=k12,dc=mo,dc=us. Check syntax.

 I am not exactly sure what I did wrong. I input the domain name as shown in the example in the link listed below for 4auHuk's script:
http://www.experts-exchange.com/Operating_Systems/Win2000/Q_20896223.html

I also double checked the correct DC name using ldp.exe  which shows as DC=malden,DC=k12,DC=mo,DC=us

The script did however create the user account. Upon checking the profile path, it was entered as needed. I have not yet tested for the homefolder being created or drive mapping as of yet taking your advice to test one line of code at a time.

For me to further test this I need to resolve this current problem with the script, or most likely, my error. I would of course open a new question and award points to resolve this new problem I have come across.
0
 
Terr0rAuthor Commented:
I just thought of something, the script I am trying to use was created for win2k. I have a win2k3 server, would this be the problem or should the script work?
0
 
Terr0rAuthor Commented:
the script is erroring here:

Set objContainer = GetObject("LDAP://cn=Users," & dcroot)

after making the user account. Upon looking at the user account, the homefolder path is inputed, but NOT the profile path.

Any ideas?
0
 
Terr0rAuthor Commented:
Hmm, upon looking at the script again, it is actually erroring after Set objContainer = GetObject("LDAP://cn=Users," & dcroot), at least I think. I am going to give it a rest for the day. I can't figure this out as I am not a scripter.
0
 
Terr0rAuthor Commented:
ok, so I couldn't just give up on it. I noticed that in the wee hours this morning before trying the script I added BOTH:

objUser.Put "homeDirectory", "\\servername\" & LogonName

AND

obUser.Put "profilePath", "\\servername\" & LogonName

I removed obUser.Put "profilePath", "\\servername\" & LogonName from the script and tried it again. The script then created all 4 test users that I keyed into the users.txt file.

Script output:

C:\>cscript /nologo makeuser.vbs
Reading user names from c:\users.txt

Line number:    Action:
==================================================
1               User "John Doe" (doej) created.
2               User "Jane Doe" (doeja) created.
3               User "Sue Ellen" (ellens) created.
4               User "Susan Ellen" (ellensu) created.



Here is the script as of this moment:

On Error Resume Next
dcroot = "DC=malden,DC=k12,DC=mo,DC=us"   ' Base path. Put "dc=subdomain,dc=domain,dc=domain" here.
Password = "xxxxxxxx"              ' Default password assigned to all created users
usrfile = "c:\users.txt"                 ' File containing users' full names list.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(usrfile) Then
    Set objFile = objFSO.OpenTextFile(usrfile, 1)
Else
    Wscript.Echo "File" & usrfile & " does not exist."
    WScript.Quit
End If

WScript.Echo "Reading user names from " & usrfile & VbCrLf
WScript.Echo "Line number:" & VbTab & "Action:"
WScript.Echo "=================================================="
Do Until objFile.AtEndOfStream
    succ = FALSE
    i = 1
    CurLine = objFile.Line
    Fullname = objFile.ReadLine
    If not FullName = "" Then
        st = InStr(FullName, " ")
        FirstName = Mid(FullName,1,st-1)
        LastName  = Mid(FullName,st+1)
        LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,1))
        Set objContainer = GetObject("LDAP://cn=Users," & dcroot)
        If Err <> 0 Then
            WScript.Echo "Can not bind to " & dcroot & ". Check syntax."
            WScript.Quit
        End If
        Err.Clear
        Do Until succ or i>3
            Set objNew = objContainer.Create("User", "cn=" & FullName)
            objNew.Put "sAMAccountName", LogonName
            objNew.SetInfo
            If Err <> 0 Then
                 i = i+1
                LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,i))
                Err.Clear
            Else
                succ = TRUE
                objNew.Put "givenName", FirstName
                objNew.Put "sn", LastName
                objNew.Put "displayName", FirstName & " " & LastName
                objNew.SetInfo
                Set objNew = Nothing
                Set objUser = GetObject("LDAP://cn=" & _
                              FullName & ",cn=Users," & dcroot)
                objUser.ChangePassword "", Password
                objUser.SetInfo
                If Err <> 0 Then
                    pwderr = "Can not set password (restrictions?). Left blank."
                    Err.Clear
                Else
                    pwderr = ""
                End If
                objUser.AccountDisabled = FALSE
                objUser.Put "pwdLastSet", 0
                objUser.Put "homeDirectory", "\\server\path\home\" & LogonName  (commented out)
                objUser.SetInfo
                Set objUser = Nothing
                WScript.Echo CurLine & vbTab & vbTab & "User """ & _
                             FullName & """ (" & LogonName & ") created. " & pwderr
            End If
        Loop
        If not succ Then
            WScript.Echo CurLine & vbTab & vbTab & _
                         "Can not create user """ & FullName & """"
        End If
    Else
        WScript.Echo CurLine & vbTab & vbTab & _
                     "Skipping Empty line in " & usrfile
    End If
Loop
objFile.Close
0
 
Terr0rAuthor Commented:
ok, with the script above, it added the users homedirectory to their local path. I then added the second string you posted; objUser.Put "homeDrive", "H", which placed their homedirectory to a mapped drive, which is what I was needing. It did not however creat the folder for their homedirectory as it would if I inputted the user by hand and added the mapped drive and folder path. Is there something else that is needed in script for this to happen?

I apologize for the very unorganized posts, and hopefully anyone reading can make out what has been happening with this problem.
0
 
Terr0rAuthor Commented:
Instead of the script entering the profile path (obUser.Put "profilePath", "\\servername\" & LogonName) can the script be edited to enter the Login script. This is what I am also needing along with the homefolder being created by the script. My apologies for stating I needed a profile patch and again, thanks for your help so far mass2612. I am learning by my mistakes here which is a good thing for future reference on this topic!
0
 
mass2612Commented:
Hi Terr0r,

objUser.Put  "scriptPath", "scriptnameandpath" should allow you to specify the logon script. Sorry but I have not had time to look into the errors here yet. Busy day so far.
0
 
Terr0rAuthor Commented:
Thanks mass2612 for your help. Work keep me busy and is very understandable that you don't have time to test anything. I got everything working except the home folder being created and of course the loginscript, which I am fixing to test with the code you posted. Thank you very much for your help so far. I will post back with the results later this evening when I get another chance to test it.  
0
 
Terr0rAuthor Commented:
Quick question mass2612,

objUser.Put  "scriptPath", "scriptnameandpath"

would be:

objUser.Put "\\servername\NETLOGON\loginscript.bat" , "loginscript.bat" ??

Do I put the path twice? Could you write an example for me? Sorry to be such a bother.
0
 
Terr0rAuthor Commented:
Anyone?
0
 
mass2612Commented:
Hi sorry for the delay.

I have this working where it sets the home share and the logon script. It should be simple to add other objects if required. No errors on a Windows 2003 test domain. You can browse down and find these lines to edit: -

objUser.Put "homeDirectory", "\\server01\home\" & LogonName
      objUser.Put "homeDrive", "H"
      objUser.Put "scriptPath", "login.bat"

You do not need to add a path to a logon script as Windows will look for the logon script in the sysvol default share.

Let us know how you get on.

Script start ****************

On Error Resume Next
dcroot = "dc=test,dc=org"   ' Base path. Put "dc=subdomain,dc=domain,dc=domain" here.
Password = "password"              ' Default password assigned to all created users
usrfile = "c:\users.txt"                 ' File containing users' full names list.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(usrfile) Then
    Set objFile = objFSO.OpenTextFile(usrfile, 1)
Else
    Wscript.Echo "File" & usrfile & " does not exist."
    WScript.Quit
End If

WScript.Echo "Reading user names from " & usrfile & VbCrLf
WScript.Echo "Line number:" & VbTab & "Action:"
WScript.Echo "=================================================="
Do Until objFile.AtEndOfStream
    succ = FALSE
    i = 1
    CurLine = objFile.Line
    Fullname = objFile.ReadLine
    If not FullName = "" Then
        st = InStr(FullName, " ")
        FirstName = Mid(FullName,1,st-1)
        LastName  = Mid(FullName,st+1)
        LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,1))
        Set objContainer = GetObject("LDAP://cn=Users," & dcroot)
        If Err <> 0 Then
            WScript.Echo "Can not bind to " & dcroot & ". Check syntax."
            WScript.Quit
        End If
        Err.Clear
        Do Until succ or i>3
            Set objNew = objContainer.Create("User", "cn=" & FullName)
            objNew.Put "sAMAccountName", LogonName
            objNew.SetInfo
            If Err <> 0 Then
                 i = i+1
                LogonName = LCase(Lastname) & LCase(Mid(FirstName,1,i))
                Err.Clear
            Else
                succ = TRUE
                objNew.Put "givenName", FirstName
                objNew.Put "sn", LastName
                objNew.Put "displayName", FirstName & " " & LastName
                objNew.SetInfo
                Set objNew = Nothing
                Set objUser = GetObject("LDAP://cn=" & _
                              FullName & ",cn=Users," & dcroot)
                objUser.ChangePassword "", Password
                objUser.SetInfo
                If Err <> 0 Then
                    pwderr = "Can not set password (restrictions?). Left blank."
                    Err.Clear
                Else
                    pwderr = ""
                End If
                objUser.AccountDisabled = FALSE
                objUser.Put "pwdLastSet", 0
                objUser.Put "homeDirectory", "\\server01\home\" & LogonName
      objUser.Put "homeDrive", "H"
      objUser.Put "scriptPath", "login.bat"
      objUser.SetInfo
      Set objUser = Nothing
                WScript.Echo CurLine & vbTab & vbTab & "User """ & _
                             FullName & """ (" & LogonName & ") created. " & pwderr
            End If
        Loop
        If not succ Then
            WScript.Echo CurLine & vbTab & vbTab & _
                         "Can not create user """ & FullName & """"
        End If
    Else
        WScript.Echo CurLine & vbTab & vbTab & _
                     "Skipping Empty line in " & usrfile
    End If
Loop
objFile.Close

Script End ************************************************
0
 
Terr0rAuthor Commented:
wow...

I didn't mean to sound ancy, just thought you had given up on me. I won't be able to test the script until this evening. I am currently busy at work supervising a new network install and this will take most of the day.

Thanks again mass2612. I will let you know tonight how it goes.
0
 
Terr0rAuthor Commented:
mass2612, the script works great.

I would like to award you extra points, I think you went far beyond answering my question totaly rewriting the script to help me.

Please follow this link and comment and I will award you extra points.
http://www.experts-exchange.com/Operating_Systems/Windows_Server_2003/Q_21923834.html 

0
 
mass2612Commented:
Hi Terr0r,

I appreciate the feedback. The original work was done by 4auHuk so a big thanks to 4auHuk. I'm glad its working for you and once again sorry for the delay. It's been a busy week and I'm studying for an exam that I'm doing on Monday so I haven't had as much time as I'd like to spend on the site. I love spending time on this site as it gives me the chance to work on issues that I don't get to deal with in the office so helping others is helping me to learn more.
0
 
Terr0rAuthor Commented:
no worries on the delay. I know what it's like studying for an exam. Now, if there was a course for vbs scripting somewhere... (going to google next)
0
 
mass2612Commented:
Hi,

To be honest I'm no guru but I can get by. 12 months ago I had no idea how to do any scripting using vbScript or WMI. I picked up the MS Press Windows Scripting Learning Guide by Ed Wilson and started reading and playing. I know there are other guides now available so I don't know how they compare.

I also grabbed a copy of the Windows 2003 SDK (Software Development Kit) from MS. It contains all the stuff you need to find the classes and objects you can use suich as "scriptPath" etc. It's good but it can be hard to find what you are looking for. Once you have the basic concepts and the SDK I found I could figure out most things I've needed to do. The MS script repository has some good examples that can get you started. I normally find something that some else has done on the Internet and then go about making it work for what I need it to do.

Why re-invent the wheel??

Good luck.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.