I am writing a script for first time on 2003 server.  it is for purpose of adding many accounts from excel spreadsheet.  I got most of it working but have a problme with display name.  When I create an account by hand and I am looking in ad&c at all users in any ou I see just fine the display name as i would expect.  When I do it from my scripts it shows what I know as the samaccount. Not sure why and can't seem to fix it.   Also having problem as the password is always blank.  I appreciate any help.   The script is below:

On Error Resume Next

Dim objXL, objUser, objOU, objArgs
Dim strADsPath, strRoot, strOU, strUserName, strXL

set objArgs=wscript.arguments
strOU = ""

CRLF = Chr(13) & Chr(10)
If objArgs.Count = 0 Then
      strXL = InputBox("This scripts reads an Excel spreadsheet and adds" & _
      "users from the Directory Service via ADSI." & CRLF & CRLF & _
      "Before starting, change the DS root in the EXCEL spreadsheet to match " & _
      "your DS." & CRLF & CRLF & _
      "Type in the path of a file containing users to add or delete" & CRLF & CRLF & _
      "Sample Add User file: C:\ADDUSERS.XLS" & CRLF & _
      "Sample Delete User file: C:\DELUSERS.XLS" & CRLF)
      strXL = objArgs.item(0)
End If

If strXL = "" Then
      MsgBox "You must provide an Excel Spreadsheet for the script to run.", vbCritical + 4096, "File Empty"
End If
Set objXL = WScript.CreateObject("EXCEL.application")
objXL.Visible = True strXL
objXL.ActiveSheet.range("A2").Activate ' this cell has the DS root in it
'WScript.Echo  objXL.activecell.Value
strRoot = objXL.activecell.Value
objXL.activecell.offset(1, 0).Activate

Do While objXL.activecell.Value <> ""
      If objXL.activecell.Value <> strOU Then
            strOU = objXL.activecell.Value
            strADsPath = "LDAP://" & strOU+"," & strRoot
              WScript.Echo strADsPath
            Set objOU = GetObject(strADsPath)
      End If
      strUserName = "CN=" + objXL.activecell.offset(0, 1).Value + "." + objXL.activecell.offset(0, 2).Value
      Set objUser = objOU.Create("User", strUserName)
      objUser.Put "givenName", objXL.activecell.offset(0, 1).Value 'givenName
      objUser.Put "sn", objXL.activecell.offset(0, 2).Value 'sn
      objUser.Put "mail", objXL.activecell.offset(0, 3).Value 'Email
        objUser.Put "userPrincipalName", objXL.activecell.offset(0, 3).Value 'UPN
      objUser.Put "sAMAccountName", objXL.activecell.offset(0, 4).Value  'Sam Acct
      objUser.Put "telephoneNumber", objXL.activecell.offset(0, 5).Value  'Phone
        objUser.Put "DisplayName", objXL.activecell.offset(0, 6).Value  'Display Name
        objUser.Put "description", objXL.activecell.offset(0,8).Value 'job title
        objUser.Put "title", objXL.activecell.offset(0,7).Value 'rank
        objUser.Put "department", objXL.activecell.offset(0,10).Value 'section
        objUser.Put "company", objXL.activecell.offset(0,9) 'unit
        objUser.setPassword "Password","Password123"
      Set objUser = Nothing
objXL.activecell.offset(1, 0).Activate   'Next row
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

The Display Name (the name as you see it) within AD is the Container Name, you're setting the Container Name to the User Name:

     strUserName = "CN=" + objXL.activecell.offset(0, 1).Value + "." + objXL.activecell.offset(0, 2).Value
     Set objUser = objOU.Create("User", strUserName)

The DisplayName property refers to how the account is seen when referred to everywhere but AD Users and Computers.

Set Password doesn't take two arguements, just one, so this will result in an error if you turn off "On Error Resume Next":

     objUser.setPassword "Password","Password123"

Instead use:


Set Password is a Method rather than a Property so isn't set quite as you'd expect. The password is also not stored in a readable string so you can't really read and write it as a property.

Hope that all makes sense.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.