Setting Display Name and Full Name attributes in VBScript

I have a script that adds new users to Active Directory in the format


and sets the user's Display Name property to

"Firstname Lastname".

However, when I open Active Directory Users and Computers, the new users appear in the list with the dotted account name, instead of with the Display Name. I tried setting the Full Name property, but nothing changed.

Here is my code:

      recip = "CN=" & emailname

      ' get the container
      Set objContainer = GetObject(ldapOU)

' create a recipient
      Set objUser = objContainer.Create("User", recip)
      FullName = FirstName & " " & LastName
      objUser.Put "displayName", FullName
      objUser.Put "samAccountName", emailname
      objUser.Put "sn", LastName
      objUser.Put "givenName", FirstName
      objUser.Put "userPrincipalName", emailname & ""

Who is Participating?
wcodyConnect With a Mentor Author Commented:
I changed my code so that the CN=FullName instead of CN=first.last, and the name displays correctly in Active Directory now.

recip = "CN=" & FullName
Set objUser = objContainer.Create("User", recip)

Do you foresee any problems with changing the common name (CN)?
Hi wcody,

objUser.Put "displayName", FullName                  what does the FullName call on? i am guessing its the first.last
wcodyAuthor Commented:

Thanks for your response. Actually, FullName is the first name followed by a space and then the last name. For example, it is in the form "John Doe".

FullName = FirstName & " " & LastName
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

sorry mate i didnt even see that variable sitting right in front of me....... i am not huge on scripting but have been doing a lot of what you are doing of late, just trying to spot something in your code, but being a newbie at this i can't see it right off!  Its 1am here in Aus, let me look again in the morning for you :)

just a check, if you specify the full name manually in your display name field, does it work? you have declared that variable yes?
nope, there shouldnt be any problems that i can see
To be honest, i dont think i even helped at all so would be more than happy for a refund to wcody, thank you though, for the gesture

Thanks Annie,

Cheers wcody

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.