Home All Groups Group Topic Archive Search About


Author
23 Nov 2007 12:54 PM
natsky
Hi
We get list where we have
lastname
firstname
username
employeeID
Is there scrip which adds empoyeeID to AD's users?
Our domain and forest are in windows 2003 server mode.

Author
23 Nov 2007 2:13 PM
Richard Mueller [MVP]
natsky wrote:

> Hi
> We get list where we have
> lastname
> firstname
> username
> employeeID
> Is there scrip which adds empoyeeID to AD's users?
> Our domain and forest are in windows 2003 server mode.
>
>

I assume the username you refer to is the "pre-Windows 2000 logon name".
This is the value of the sAMAccountName attribute of the user object. You
can use the NameTranslate object to convert this to the Distinguished Name
of the user, which is required to bind to the user object to modify the
employeeID attribute. Unless you intend to change the firstname and
lastname, there should be no need for these values (they are not required
and do not uniquely identify the user). However, the corresponding
attributes are givenName (firstname) and sn (lastname).

Information on using the NameTranslate object here:

http://www.rlmueller.net/NameTranslateFAQ.htm

If you have a text file with username and employeeID, separated by a space,
one line per user, you can use the FileSystemObject to parse the file. For
example:
============
Const ForReading = 1


' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1



' Specify the file name and path.
' Each line of the file has username (sAMAccountName),
' a space, then the employeeID.
strFileName = "c:\scripts\users.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)


' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)


' Read the file.
Do Until objFile.AtEndOfStream
    strLine = (objFile.ReadLine)
    ' Parse the line into space delimited values
    arrValues = Split(strLine, " ")
    strName = arrValues(0)
    strEmployeeID = arrValues(1)

    ' Use the Set method to specify the NT format of the object name.
    objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strName
    ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
    strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)

    ' Bind to the user object.

    Set objUser = GetObject("LDAP://" & strUserDN)

    ' Assign Employee ID.

    objUser.employeeID = strEmployeeID

    ' Save change.

    objUser.SetInfo
Loop


' Clean up.
objFile.Close

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Author
26 Nov 2007 7:28 AM
natsky
Thank you
This helps me.

Show quote
"Richard Mueller [MVP]" wrote:

> natsky wrote:
>
> > Hi
> > We get list where we have
> > lastname
> > firstname
> > username
> > employeeID
> > Is there scrip which adds empoyeeID to AD's users?
> > Our domain and forest are in windows 2003 server mode.
> >
> >
>
> I assume the username you refer to is the "pre-Windows 2000 logon name".
> This is the value of the sAMAccountName attribute of the user object. You
> can use the NameTranslate object to convert this to the Distinguished Name
> of the user, which is required to bind to the user object to modify the
> employeeID attribute. Unless you intend to change the firstname and
> lastname, there should be no need for these values (they are not required
> and do not uniquely identify the user). However, the corresponding
> attributes are givenName (firstname) and sn (lastname).
>
> Information on using the NameTranslate object here:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm
>
> If you have a text file with username and employeeID, separated by a space,
> one line per user, you can use the FileSystemObject to parse the file. For
> example:
> ============
> Const ForReading = 1
>
>
> ' Constants for the NameTranslate object.
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
>
>
> ' Specify the file name and path.
> ' Each line of the file has username (sAMAccountName),
> ' a space, then the employeeID.
> strFileName = "c:\scripts\users.txt"
>
> ' Open the file for read access.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)
>
>
> ' Determine DNS name of domain from RootDSE.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
> ' Use the NameTranslate object to find the NetBIOS domain name from the
> ' DNS domain name.
> Set objTrans = CreateObject("NameTranslate")
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> ' Remove trailing backslash.
> strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
>
>
> ' Read the file.
> Do Until objFile.AtEndOfStream
>     strLine = (objFile.ReadLine)
>     ' Parse the line into space delimited values
>     arrValues = Split(strLine, " ")
>     strName = arrValues(0)
>     strEmployeeID = arrValues(1)
>
>     ' Use the Set method to specify the NT format of the object name.
>     objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strName
>     ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
>     strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
>
>     ' Bind to the user object.
>
>     Set objUser = GetObject("LDAP://" & strUserDN)
>
>     ' Assign Employee ID.
>
>     objUser.employeeID = strEmployeeID
>
>     ' Save change.
>
>     objUser.SetInfo
> Loop
>
>
> ' Clean up.
> objFile.Close
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

AddThis Social Bookmark Button