views:

57

answers:

1

I have a .csv file with EmployeeNumber, TelephoneNumber, IPPhone Number listed in a text file I need a way to loop thru all the records in the text file and modify the 2 phone attributes in LDAP please help. This is totally frustrating

+1  A: 

If you're using .NET 3.5 (or you can update to it), check out the System.DirectoryServices.AccountManagement namespace - makes a lot of things a lot easier.

Read up on it: Managing Directory Security Principals in the .NET Framework 3.5 and check out all the properties surfaced by the new UserPrincipal class in .NET 3.5.

The other place I'd recommend is Richard Mueller's web site - he has lots of Excel sheets which show all the AD / LDAP attributes, where on the interactive tools you'll find those, and so forth. Highly useful!

Combine those two resources, and you should be able to do whatever it is you need to do!

Update: if you cannot update to .NET 3.5 (which is really just like a service pack on top of .NET 2....), you would have to do the following steps:

  • import the CSV into a List<CSVRecord> - I'd use the free FileHelpers library to do that; your CSVRecord would hold the three fields in your CSV file
  • create a DirectorySearcher class based on your search root (your domain or a sub-container thereof); find the correct LDAP search filter to find your user by EmployeeId

  • loop over the entries in your list, and for each entry

    • search the directory for that user
    • if found: grab the DirectoryEntry from your SearchResult and update the two attributes
    • call .CommitChanges() on that DirectoryEntry

I don't think there's any other way, really, to do this - there's no magic way to select all users at once, or update them all at once.

Update #2:
Here are some resources you can check out:

and the ultimate book on the subject:

Joe Kaplan / Ryan Dunn: The .NET Developer's Guide to Directory Services Programming

alt text

marc_s
Can you provide a little bit of a code snippet. I have not problem getting the user properties from LDAP I just can't reverse my thinking to update a whole group of users from a .csv file. I appreciate your repsonse as well.
EverGlade
I am using .net 2.0 btw. they have not updated our servers to use .Net 3.5 even though we are coding with VS 2008
EverGlade
I HAVE TRIED EVERYTHING I DON'T UNDERESTAND WHERE TO START HOW COME THERE ARE NOT ANY GOOD EXAMPLES ON THE NET. LDAP AND ACTIVE DIRECTORY MUST BE VERY POOR TOOLS I GUESS. HELP....!!!! Please
EverGlade
The tools aren't poor - the subject isn't the easiest to master, agreed. Check out my additional resources I put in my post
marc_s