PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Re: Add employeeID to users
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: Add employeeID to users

Réponse
 
LinkBack Outils de la discussion
Vieux 23/11/2007, 14h13   #1
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add employeeID to users

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
--


  Réponse avec citation
Vieux 26/11/2007, 07h28   #2
natsky
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add employeeID to users

Thank you
This s me.

"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
> --
>
>
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12253 seconds with 10 queries