修改使用C#LDAP联系号码和IPPHONE属性 [英] Modify LDAP PhoneNumber and IPPhone attribute using C#
问题描述
我有EmployeeNumber,TelephoneNumber,IPPHONE号码.csv文件中我需要一种方法来环通在文本文件中的所有记录,并修改2手机属性的LDAP请帮一个文本文件中列出。这完全是令人沮丧的。
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
推荐答案
如果您使用的是.NET 3.5(或者你可以更新它),检查了 System.DirectoryServices.AccountManagement
命名空间 - 让很多事情变得更容易。
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.
在别的地方,我建议是理查德·穆勒的网站 - 他有很多的Excel这显示所有的AD / LDAP属性,这里的互动工具,你会发现这些,等张。非常有用的!
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!
更新:如果您不能更新到.NET 3.5(这是真的,就像在.NET 2 ....顶一个服务包),你就必须执行以下步骤:
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:
- 导入CSV成
名单,其中,CSVRecord>
- 我用免费的 FileHelpers 库来做到这一点;你的CSVRecord
将握在CSV三个字段文件 -
根据您的搜索根目录下创建一个
DirectorySearcher从
类(您的域或子容器体);找到正确的过滤器LDAP搜索来寻找雇员
- import the CSV into a
List<CSVRecord>
- I'd use the free FileHelpers library to do that; yourCSVRecord
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 byEmployeeId
循环遍历列表中的条目,每个条目
loop over the entries in your list, and for each entry
- 在目录中搜索该用户
- 如果发现:抢
的DirectoryEntry
从信息搜索结果
和更新两个属性 - 呼叫
.CommitChanges()
上的DirectoryEntry
- search the directory for that user
- if found: grab the
DirectoryEntry
from yourSearchResult
and update the two attributes - call
.CommitChanges()
on thatDirectoryEntry
我不认为有任何其他的方式,真的,要做到这一点 - 有什么神奇的方法来选择所有用户一次,或更新它们一次全部
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.
更新#2:
这里有一些资源,你可以看看:
Update #2:
Here are some resources you can check out:
- Quick List of lots of C# code samples
- How to do almost anything in Active Directory using C#
- Search results for "Active Directory" on Codeproject
和关于这一问题的终极书:
and the ultimate book on the subject:
这篇关于修改使用C#LDAP联系号码和IPPHONE属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!