DirectoryEntries.Find:"一个无效的dn语法已指定" [英] DirectoryEntries.Find: "An invalid dn syntax has been specified"

查看:2475
本文介绍了DirectoryEntries.Find:"一个无效的dn语法已指定"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出在当前域中的用户。在code是这样的:

I'm trying to find a user in the current domain. The code is this:

DirectoryEntry domain = new DirectoryEntry("LDAP://CN-Users, DC=" + Environment.UserDomainName);
            DirectoryEntries entries = domain.Children;
            try
            {
                // The following line causes the exception
                DirectoryEntry user = entries.Find("(&(objectCategory=user)(cn=" + userName + "))", ActiveDirectoryEntryType.User.TypeName);
                user.DeleteTree();
                user.CommitChanges();
            }
            catch
            {}

我得到一个错误:

I'm getting an error:

An invalid dn syntax has been specified.

我也试过以下code,并得到了同样的错误:

I also tried the following code and got the same error:

DirectoryEntry user = entries.Find(userName, ActiveDirectoryEntryType.User.TypeName);

我无法找到有关的帮助文件的正确语法的信息。有谁知道如何做到这一点?

I could not find information about the proper syntax in the help files. Does anyone know how this is done?

推荐答案

您在本statemet错误:

You have an error in this statemet:

DirectoryEntry domain = new DirectoryEntry("LDAP://CN-Users, DC=" + Environment.UserDomainName);

我几乎可以肯定,它应该是: LDAP:// CN =用户​​, instaed 的LDAP:// CN-用户,

I almost sure that it should be: LDAP://CN=Users, instaed of LDAP://CN-Users,

第二件事是 DC =+ Environment.UserDomainName 这可能错了,因为通常游戏是这样的: LDAP:// OU =金融,DC = Fabrikam目录,DC = COM (有多个DC)

Second thing is DC=" + Environment.UserDomainName which maybe wrong, because ususally it is something like this: LDAP://OU=Finance,dc=fabrikam,dc=com (there is more than one DC)

您可以使用PowerShell的找到所有的DC。运行以下命令:

You can find all DC using powershell. Run following command:

New-Object DirectoryServices.DirectoryEntry

这篇关于DirectoryEntries.Find:"一个无效的dn语法已指定"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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