Re: Modifying AD User attribute
- From: spock <spock@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Mar 2007 13:40:01 -0700
Richard,
I tested the script and it work great!!
Thanks.
Other question:
Would you haapened to have a script to do the following:
In order to create the names.txt file, I am going to have to combine 2
different spread sheets, from two different systems. If name matches, create
new record:
First Name Last Name MI AD Login ID ID Number
John Brown A jbrown 123456789
If no MI and duplicate John Brown, skip and write to file
c:\scripts\exceptions.txt
From AD:
First Name Last Name MI AD Login ID
John Brown A jbrown
From HR System:First Name Last Name MI ID Number
John Brown A 123456789
New File:
First Name Last Name MI AD Login ID ID Number
John Brown A jbrown 123456789
Thanks again.
"Richard Mueller [MVP]" wrote:
spock wrote:.
Does anyone have a script that reads and Execl spread *** and matches
username in AD with username in the spread***, then modifies the
"wwwhomepage" and put a value in the AD general user attribute (web page
field)?
Clarification:
I want read a list of usernames from a file and then search the entire AD
tree for a user (by Lastname, Firstname and or username) in a file, if I
find
the user, I want to modify the Web Page field (under general user) and add
a
value (read from the same file).
Example:
File:
FirstName Lastname username ID Number
John Brown jbrown 123456789
Search for jbrown, if exist, then move 123456789 to Web Page
(wwwhomepage)field.
or
Search for John and Brown, if exist, then move 123456789 to web page,
(wwwhomepage) filed if John Brown is a duplicate, write to a file.
Thanks.
I assume what you call the username is the value of the sAMAccountName
attribute of the user. This is also called the NT name of the user or the
"pre-Windows 2000 logon name". If so, you can use the NameTranslate object
(combined with the NetBIOS name of the domain) to convert to the
Distinguished Name required by the LDAP provider. Details linked here:
http://www.rlmueller.net/NameTranslateFAQ.htm
This would be more efficient than searching all of AD. However, a potential
problem I see is how to parse your file. You can use the FileSystemObject to
read the file one line at a time, but can we be sure all values are
delimited by spaces? Is it possible that some names could have embedded
spaces, like say "Mary Ann"? I personally have seen many examples. If you
can, it would be best to use a delimiter like the semicolon ";".
Assuming we can use the ";" character as a delimiter, the program could be
similar to:
==================
Option Explicit
Dim objRootDSE, strDNSDomain, strNetBIOSDomain
Dim objTrans, strFile, objFSO, objFile
Dim strLine, arrValues, strValue
Dim strFirst, strLast, strUser, strID
Dim strUserDN, objUser
Const ForReading = 1
' Constants for NameTranslate.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify input file.
strFile = "c:\Scripts\Names.txt"
' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Determine DNS domain name from RootDSE object.
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
' Skip blank lines.
If (strLine <> "") Then
' Parse the line into an array of values.
arrValues = Split(strLine, ";")
' There must be 4 values per line.
If (UBound(arrValues) = 3) Then
strFirst = Trim(arrValues(0))
strLast = Trim(arrValues(1))
strUser = Trim(arrValues(2))
strID = Trim(arrValues(3))
' Use NameTranslate to convert NT name to DN.
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strUser
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to user object.
Set objUser = GetObject("LDAP://" & strUserDN)
' Assign wWWHomePage
objUser.wWWHomePage = strID
objUser.SetInfo
End If
End If
Loop
' Clean up.
objFile.Close
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
- Follow-Ups:
- Re: Modifying AD User attribute
- From: Richard Mueller [MVP]
- Re: Modifying AD User attribute
- References:
- Re: Modifying AD User attribute
- From: Richard Mueller [MVP]
- Re: Modifying AD User attribute
- Prev by Date: Re: Batch file syntax for escape character HELP needed!
- Next by Date: Account Expiry/User creation script
- Previous by thread: Re: Modifying AD User attribute
- Next by thread: Re: Modifying AD User attribute
- Index(es):