Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change the cn attribute

550 views
Skip to first unread message

Roger

unread,
Dec 3, 2003, 1:56:07 PM12/3/03
to
Can someone tell me how the code would look to change the UserID in Active Directory from say lastname to firstinitiallastname.
 
For instance: the code in RED below.  Instead of echoing the value I want to change it.
 
Set objSysInfo = CreateObject ("ADSYstemInfo")
 
 
 
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
objUser.GetInfo
 
'Set objDomain = GetObject("LDAP://" & objSysInfo.DomainDNSName)
'objDomain.GetInfo
 
 
 
strDisplayName = objUser.Get("displayName")
strDescription = objUser.Get("description")
strUserName = objUser.Get("cn")
strUserOu = objUser.Get("DistinguishedName")
strUserPrincipalName = objUser.Get("UserPrincipalname")
strUserLastName = objUser.Get("sn")
strUserFirstName = objUser.Get("givenName")
strUserEmail = objUser.Get("mail")
 
 
 

'WScript.Echo strUsername
'WScript.Echo strDnsDomainName
'WScript.Echo strDomainShortName
'WScript.Echo strDisplayName
'WScript.Echo strDescription
 

WScript.Echo "User Logon ID:..............................." & strUserName & vbCrLf & _
"User Principal Name:........................." & strUserPrincipalName & vbCrLf & _
"User Full Name:..............................." & strUserLastName & ", " & strUserFirstName & vbCrLf & _
"Users Email Address:........................." & strUserEmail & vbCrLf & _
"User Account in OU:........................." & strUserOu & vbCrLf & _
"User Site:......................................" & objSysInfo.SiteName & vbCrLf & _
"User Description.............................." & strDescription & vbCrLf & _
"Current Logon DNS Domain Name:........" & objSysInfo.DomainDnsName & vbCrLf & _
"Current Logon NetBIOS Domain Name:..." & objSysInfo.DomainShortName

Richard Mueller [MVP]

unread,
Dec 3, 2003, 5:01:41 PM12/3/03
to
Hi,
 
You cannot modify the cn attribute like you can others. Because it is the Relative Distinguished Name of the object, you must use the MoveHere method of the parent container to rename the object. For example, to rename the current user to "cn=JSmith":
 
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objParent = GetObject(objUser.Parent)
Set objNewUser = objParent.MoveHere(objUser.AdsPath, "cn=JSmith")

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
 

Roger

unread,
Dec 3, 2003, 5:21:30 PM12/3/03
to
Thanks for your reply Richard.
 
Just to give you a little background.  It's been mandated by our parent company that we change our domain user IDs to match our Lotus Notes logon name (called the short name)
 
I've tested renaming a user account in Active Directory users and computers and it works great.  Once renamed it maintains the same SID so any permissions to resources will not need to be changed.
 
I thought I could automate this process via a script.  My thinking is that I could reference a spreadsheet containing all the attribute values that need to be changed by the script including the "cn" and the "sAMAccountName".
 
Can I do this using your example?  If so, what is the next step in your example that would actually change the value?
 
How far out on a limb am I here?
 
Your thoughts would be appreciated.
 
Thanks,
 
Roger
 
 

"Richard Mueller [MVP]" <rlmuelle...@ameritech.net> wrote in message news:Ocp$zkeuDH...@TK2MSFTNGP11.phx.gbl...

Richard Mueller [MVP]

unread,
Dec 3, 2003, 8:30:46 PM12/3/03
to
Hi,
 
I have an example program to modify user objects with values from a spreadsheet linked on this page:
 
 
The program reads the user Distinguished Name from the first column of the spreadsheet. This example modifies the "profilePath" attribute, but almost any attribute, including sAMAccountName, can be updated this way. The program also shows how to "null" an attribute (remove any value). If you plan to modify the "cn" attribute, of course, you will have to use the MoveHere method of the parent container object.
 
Also, you are correct about the SID's.
 
Does your spreadsheet identify users by DN or sAMAccountName? Are the first name (givenName) and last name (sn) attributes populated with values in your AD, so you can use these values to construct the new names, or will everything be supplied in the spreadsheet? Is your intention that the value of sAMAccountName be the same as the value of cn?

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--

Roger

unread,
Dec 4, 2003, 9:47:50 AM12/4/03
to
 
"Richard Mueller [MVP]" <rlmuelle...@ameritech.net> wrote in message news:un0ZrZg...@TK2MSFTNGP11.phx.gbl...
Hi,
 
I have an example program to modify user objects with values from a spreadsheet linked on this page:
 
 
The program reads the user Distinguished Name from the first column of the spreadsheet. This example modifies the "profilePath" attribute, but almost any attribute, including sAMAccountName, can be updated this way. The program also shows how to "null" an attribute (remove any value). If you plan to modify the "cn" attribute, of course, you will have to use the MoveHere method of the parent container object.
 
Also, you are correct about the SID's.
 
Does your spreadsheet identify users by DN or sAMAccountName? By DN, however, these values are the same throughout the domain. (Supposed to be anyway :) )  Are the first name (givenName) and last name (sn) attributes populated with values in your AD, No, some are but I would say most are NOT. these are values that we want to provide in the spreadsheet to clean things up.  so you can use these values to construct the new names, or will everything be supplied in the spreadsheet? Everything provided in speadsheet.  Is your intention that the value of sAMAccountName be the same as the value of cn?  Yes, we want these to match.

Max L. Vaughn [MSFT]

unread,
Dec 11, 2003, 8:46:56 AM12/11/03
to
It kindof rambles....

What is the end question? Is there some way to shorten the post and just
list what the final question is?

Sincerely,
Max Vaughn [MS]
Microsoft Developer Support


Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.

0 new messages