AD scripting question

J

Joe Granto

I am working on a VB script that creates users. I have gone to the MS
site and looked at their sample code, and searched on the internet,
and have the script so that it works relatively well. However, I am
still unable to do one thing I would really like to do. I should
probably add that I am not all that fluent with VBScript...

When I open AD Users and Computers (ADUC), call up a user account,
there are many fields. The fields I am interested in, as labeled in
ADUC, are:

General Tab
Display name
Description
Account Tab
User logon name

The script listed below is able to add data all three fields. The
problem, however, is that the account created does not show up in ADUC
as listed in "Display name"; rather, it is listed as "User logon
name".

For example, say I create the following account:
Display name = Bar, Foo
Description = Test account
User logon name = Foo.Bar

The script runs without errors, and under ADUC, the account is
displayed with all the other accounts as "Foo.Bar" and not "Bar, Foo".
When I open the properties of the account, the "Display name" field
shows the account as "Bar, Foo" even though it is not displayed that
way.

My question: how can I get the account I create to be displayed in
ADUC with the "Display name" data instead of the "User logon name"
data?

Thanks for the help!

Here is the section of my script that makes the AD mods:
-------------------------
Set oOU = GetObject("LDAP://" & vOU)
Set oUser = oOU.Create("User", "cn=" & vUName)
oUser.Put "sAMAccountName", vUName
If Not(vDescription = "") then
oUser.PutEx ADS_PROPERTY_UPDATE, "description", Array(vDescription)
End If
oUser.Put "displayName", vDName
oUser.Put "userPrincipalName", VUName & "@dsmain.com"
oUser.SetInfo

'On Error resume next
Set oUser = GetObject("LDAP://cn=" & vUName & "," & vOU)
oUser.AccountDisabled = FALSE
oUser.SetPassword vPassword
oUser.SetInfo



Please replace the "NoSpam" with "MCI" in my email address in order to
reply.
 
T

Tim Mintner

What you need to do is set cn= Barr, Foo. What you have now in this part of
the script is

Set oUser = oOU.Create("User", "cn=" & vUName)

This is setting the cn= vUName which happens to be the same thing as
SamAccountName. The display name in Active Directory is actually the CN.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top