I do something very similar every morning. I get a daily download from
our main business system that is pushed into SQL Server. I then use CF
to make changes, to AD, where needed. Eventually, I will do all of this
in SQL Server as an SSIS package, but for now, CF is perfect.
First, load your CSV into a query by reading with CFFILE then looping
over it or using CFHTTP.
Then, use CFLDAP to pull out all of your user accounts and retrieve all
of those attributes that you may need to update.
Next, you start looping over each record from your CFLDAP query. Within
each loop iteration, use QofQ to get the matching record from your CSV
query.
Compare the values from AD and CSV. If there are any differences, then
write them to a buffer object (list, array, struct, etc) for later use.
Do this for each attribute you need to update. This way, you can build
a single ATTRIBUTES string that you pass to CFLDAP for each AD object
that needs to be updated.
Also, I recommend that you do a case-sensitive comparison. You will
find any changes such as Mcdonald -> McDonald. (We get lots of these
with our foreign students.)
Finally, pass the ATTRIBUTES string into the CFLDAP tag to do the actual
update and move on to the next record.
Here is a simple breakdown of the process.
<cfhttp...> <!--- get the csv file --->
<cfldap...> <!--- get all users from Active Directory --->
<cfloop query="ldapResults">
<newAttributes = ""> <!--- reset our attributes string --->
<cfquery datasource="csvSource"> <!--- get any updated values from
the csv source --->
SELECT *
FROM csvQuery <!--- this is the name of your query from the cfhttp
tag --->
WHERE id = #ldapResults.employeeID#
</cfquery>
<cfif compare(ldapResults.title, csvSource.title) neq 0> <!--- see if
anything is different --->
<cfset newAttributes = newAttributes & "title=#csvSource#;">
</cfif>
<cfif compare(ldapResults.telephoneNumber, csvSource.telephoneNumber)
neq 0> <!--- see if anything is different --->
<cfset newAttributes = newAttributes & "title=#csvSource#;">
</cfif>
<cfif len(newAttributes) gt 0> <!--- if any differences were found,
update the AD object --->
<cfldap action="modify" attributes="#newAttributs#"...>
</cfif>
</cfloop>
m!ke
-----Original Message-----
From: Ian Vaughan [mailto:[EMAIL PROTECTED]
Sent: Friday, March 07, 2008 4:14 AM
To: CF-Talk
Subject: Coldfusion and Active Directory
I am using CF 7 Enterprise and I am looking to bulk update active
directory with content contained in a .csv file.
The csv file contains content such as telephone number, e-mail address,
name, job title, section etc.
How can I use CFLDAP to bulk update records in Active Directory from the
content in the csv file.
i.e. updating or adding the employee phone number in their Active
Directory listing with their correct phone number contained in the CSV
file.
And how would the script know which records to update in AD with the
correct data for that employee?
The unique field for each employee is their 'employeeno' which is
contained in both the csv and as an Active Directory attribute.
Any ideas ?
I.E.
<cfldap
action="modify"
modifyType="replace"
attributes="telephoneNumber=#CSVTelno#"
DN="dc=domain,dc=co,dc=uk"
server="server"
port="389"
username="username"
password="password">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:300725
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4