Active Directory 2008 R2,c#

Active Directory 2008 R2,c#

我正在使用 C# 并尝试检查活动目录中是否存在某个组我正在这样做

string cmd = "New-Object DirectoryServices.DirectoryEntry \"LDAP://cn=" + groupname + " " + LdapDef + ",dc=twu,dc=ca\" | Select-Object name";
string result = execute(cmd);
return true;

这在过去是可行的,但是从一段时间以来,每当执行上述代码时,我都会收到以下错误。

Server was unable to process request. ---> The following exception occurred while    retrieving member "name": "There is no such object on the server.

" ---> The following exception occurred while retrieving member "name": "There is no such object on the server.

" ---> There is no such object on the server.

我不确定这里出了什么问题?除了使用“名称”之外,我还能用什么来获取组名

有人可以帮我吗?

答案1

这是我用来搜索目录的方法:

 DirectoryEntry objDE;
 objDE = new DirectoryEntry("LDAP://cn=computers,dc=lab,dc=test");
 static String[] strProperties = { "name" };

 DirectorySearcher dd = new DirectorySearcher(objDE, "(&(objectCategory=group)(objectClass=user)(cn=name))", strProperties, SearchScope.Subtree);

这是 C#,我从来没有混合过 C# 和 powershell,但这应该可以为你指明正确的方向。别忘了

Using System.DirectoryServices

还。

http://msdn.microsoft.com/en-us/library/windows/desktop/aa746475(v=vs.85).aspx

相关内容