净code设置的Active Directory属性"未设置" [英] .Net code to set an Active Directory attribute to "not set"

查看:216
本文介绍了净code设置的Active Directory属性"未设置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在活动Direcotry MMC管理单元中,你不能看到的属性是未设置。当您使用Adsiedit.msc工具,如果属性值是空的,你确实看到他们为未设置。

In the Active Direcotry mmc snap-in you cant see attributes that are "Not Set". When you use ADSIEDIT.MSC tool, if attribute values are null you do see them as "Not Set".

如何设置一个属性,在.net code未设置?

下面是PowerShell中的答案,但我需要一些净code(VB.Net/C#)做到这一点。 <一href="http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/d6d0bfa1-73da-41ea-a7f5-f622de9f7d1b/" rel="nofollow">http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/d6d0bfa1-73da-41ea-a7f5-f622de9f7d1b/

Here is the answer in Powershell but I need to do it with some .Net code (VB.Net/C#). http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/d6d0bfa1-73da-41ea-a7f5-f622de9f7d1b/

PS msExchHideAddressLists是罪魁祸首属性,当它的真或假在这一领域是prevents用户信息从AD复制到SharePoint。

ps msExchHideAddressLists is the culprit attribute, when its True or False in this domain it prevents user information replicating from AD to Sharepoint.

推荐答案

MSDN < /一>,你可以发现:

In the MSDN you can found :

在支持LDAP的常用目录,没有值的属性不存在。当该属性值是由一个变化设定为非零值,更换或追加操作,属性,如果它不存在,则将创建。同样地,如果属性被修改为没有值(或值),其全部属性被删除。有时,你可能要设置一个属性为null。虽然这个概念并不在支持LDAP的目录存在,可以通过删除属性完全与指定的属性将被清除完成此。

Within commonly used directories that support LDAP, an attribute without a value does not exist. When the attribute value is set to a non-null value by a change, replace, or append operation, the attribute is created if it does not already exist. Similarly, if an attribute is modified to have no value (or values), the entire attribute is removed. At times you may want to set an attribute to null. While this concept does not exist in directories that support LDAP, you can accomplish this by removing the attribute entirely and specifying that the property is to be cleared.

下面是一个使用的System.DirectoryServices 的例子:

Here is an example using System.DirectoryServices :

/* Connection to Active Directory
 */
DirectoryEntry deBase = new DirectoryEntry("LDAP://192.168.183.220:389/dc=societe,dc=local", "administrateur", "adm");

/* Directory Search
 */
DirectorySearcher dsLookForOUs = new DirectorySearcher(deBase);
dsLookForOUs.Filter = "(objectCategory=organizationalUnit)";
dsLookForOUs.SearchScope = SearchScope.Subtree;
dsLookForOUs.PropertiesToLoad.Add("cn");
dsLookForOUs.PropertiesToLoad.Add("ou");
dsLookForOUs.PropertiesToLoad.Add("telephoneNumber");

SearchResultCollection srcOUs = dsLookForOUs.FindAll();

foreach (SearchResult srOU in srcOUs)
{
  Console.WriteLine("{0}", srOU.Path);
  DirectoryEntry de = srOU.GetDirectoryEntry();
  if (de.Properties["TelephoneNumber"].Value!= null)
  {
    // Both solutions are working. Don't forget to commit

    //de.Properties["TelephoneNumber"].Clear();
    de.Properties["TelephoneNumber"].Value=null;
    de.CommitChanges();
  }
}

这篇关于净code设置的Active Directory属性&QUOT;未设置&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆