更新 Active Directory 中的全名

发布于 2024-08-11 03:50:31 字数 171 浏览 1 评论 0原文

我已经陷入 Active Directory 的深渊(我是一名 Web 开发人员,请参阅)我有一个用户,我已经更改了名字/姓氏,但全名没有更改,这导致了问题共享 BCM 数据库。我如何刷新它以便更新全名。

我不知道 AD 是如何工作的,但出于某种原因,上级决定这是我的工作。

任何帮助将非常感激。

I've been thrust into the deep end with Active Directory (I'm a web developer, go fig) I have a user that I've changed first/last name on but the Full Name hasn't changed which is causing issues with sharing off a BCM database. How do I refresh it so the Full Name is updated.

I have no idea how AD works but for some reason the higher ups have decided it's my job.

Any help would be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2024-08-18 03:50:31

您使用的是 .NET 3.5 吗?如果是这样,请查看这篇 MSDN 文章:管理 .NET 中的目录安全主体框架3.5

查看这篇 CodeProject 文章:Howto:(几乎)通过 C# 实现 Active Directory 中的所有内容

查看 MSDN 上 System.DirectoryServices 的代码示例列表

如果您认真对待 C# 或 VB.NET 中的 Active Directory 编程,请购买这本书:

目录服务编程 .NET 开发人员指南

替代文字

更新“全名”(实际上是:DisplayName)应该像(在 .NET 3.5 上)一样简单:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourDomain");

UserPrincipal up = UserPrincipal.FindByIdentity(ctx, "(your user name)");

if (up != null)  // we found the user
{
   up.DisplayName = "new display name for your user";
   up.Save();
}

就是这样! :-)

请注意:您需要将 NetBIOS 域名(例如“MICROSOFT”) - 而不是 DNS 样式名称 (microsoft.com) 传递给 PrimaryContext 的构造函数。

希望这有帮助!

Marc

.NET 2.0 的更新:

如果您在 .NET 2.0 上运行,并且需要更新用户的“displayName”,给定他的“SAMAccountName”(没有域的用户名,基本上):

// set the root for the search
DirectoryEntry root = new DirectoryEntry("LDAP://dc=yourcompany,dc=com");

// searcher to find user in question
DirectorySearcher ds = new DirectorySearcher(root);

// set options
ds.SearchScope = SearchScope.Subtree;
ds.Filter = string.Format("(&(sAMAccountName={0})(objectCategory=Person))", yourUserName);

// do we find anyone by that name??
SearchResult result = ds.FindOne();

if (result != null)
{
    // if yes - retrieve the full DirectoryEntry for that user
    DirectoryEntry userEntry = result.GetDirectoryEntry();

    // set the "displayName" property to the new value
    userEntry.Properties["displayName"].Value = yourNewUserFullName;

    // save changes back to AD store
    userEntry.CommitChanges();
}

Are you on .NET 3.5 ? If so, go check out this MSDN article: Managing Directory Security Principals in the .NET Framework 3.5.

Check out this CodeProject article: Howto: (Almost) Everything In Active Directory via C#

Check out this list of Code Samples for System.DirectoryServices on MSDN.

If you're serious about Active Directory Programming in C# or VB.NET, go buy this book:

The .NET Developer's Guide to Directory Services Programming

alt text

Updating the "full name" (really: DisplayName) should be as easy as (on .NET 3.5):

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "yourDomain");

UserPrincipal up = UserPrincipal.FindByIdentity(ctx, "(your user name)");

if (up != null)  // we found the user
{
   up.DisplayName = "new display name for your user";
   up.Save();
}

That's it! :-)

Mind you : you need to pass in the NetBIOS domain name (e.g. "MICROSOFT") - not a DNS-style name (microsoft.com) to the constructor of the PrincipalContext.

Hope this helps!

Marc

UPDATE for .NET 2.0:

Here's the code if you're running on .NET 2.0 and need to update the "displayName" for a user, given his "SAMAccountName" (his username without the domain, basically):

// set the root for the search
DirectoryEntry root = new DirectoryEntry("LDAP://dc=yourcompany,dc=com");

// searcher to find user in question
DirectorySearcher ds = new DirectorySearcher(root);

// set options
ds.SearchScope = SearchScope.Subtree;
ds.Filter = string.Format("(&(sAMAccountName={0})(objectCategory=Person))", yourUserName);

// do we find anyone by that name??
SearchResult result = ds.FindOne();

if (result != null)
{
    // if yes - retrieve the full DirectoryEntry for that user
    DirectoryEntry userEntry = result.GetDirectoryEntry();

    // set the "displayName" property to the new value
    userEntry.Properties["displayName"].Value = yourNewUserFullName;

    // save changes back to AD store
    userEntry.CommitChanges();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文