Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > copy files with AD attributes in name??
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 30th October 05:51
steveb
External User
 
Posts: 1
Default copy files with AD attributes in name??



I have a folder full of employee pictures.
The name format is from active directory, as
"sn, givenname.JPG"

Now I have a web app that can not access the first and last name to display the picture.
It only knows the SAMAccountName.

Does anyone have a clue where to start with a script to copy these files from
"sn, givenname.JPG" to "SAMAccountName.jpg" ??

--
--
Steven

http://www.glimasoutheast.org
  Reply With Quote


 


2 30th October 05:51
richard muellerf!j·l¹éez·b±Ë¬²*²hœ®‹(~×(
External User
 
Posts: 1
Default copy files with AD attributes in name??



The only solution I can think of is a script that reads the file name and
parses the values of the sn and givenName attributes, then uses ADO to search
Active Directory for the user object that has these values. You would return
the value of sAMAccountName. For information on using ADO for this, see this
link:

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

The problem is that you may find no users, one user, or several users that
match your query. Many users could have the same first and last names
(assuming these fields are filled in, as they are not required). In brief,
the query would be (using syntax similar to what I use in the link above):

' You would parse the file name for these values.
strFirst = "Jim"
strLast = "Smith"

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

strFilter = "(&(objectCategory=person)(objectClass=user)(given Name=" _
& strFirst & ")(sn=" & strLast & "))"

strAttributes = "sAMAccountName,cn"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

The code should account for the 3 possibilities: there is one record in the
resulting recordset, no records, or more than one.

Richard Mueller (MVP)
  Reply With Quote
Reply


Thread Tools
Display Modes




666