Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Ldap:从C中的父组检索子组#_C#_Active Directory_Ldap - Fatal编程技术网

C# Ldap:从C中的父组检索子组#

C# Ldap:从C中的父组检索子组#,c#,active-directory,ldap,C#,Active Directory,Ldap,我在Active Directory帐户中有安全组。安全组包括用户和子组。我可以从安全组获取用户。这是从安全组获取用户的代码,我将“groupname”作为参数传递。它将返回属于该组的相应用户 DataTable dt = new DataTable(groupName); var _with1 = dt.Columns; _with1.Add("AccountID", typeof(string)); _with1.Add("FirstNam

我在Active Directory帐户中有安全组。安全组包括用户和子组。我可以从安全组获取用户。这是从安全组获取用户的代码,我将“groupname”作为参数传递。它将返回属于该组的相应用户

  DataTable dt = new DataTable(groupName);
        var _with1 = dt.Columns;
        _with1.Add("AccountID", typeof(string));
        _with1.Add("FirstName", typeof(string));
        _with1.Add("LastName", typeof(string));
        _with1.Add("DisplayName", typeof(string));
        _with1.Add("Email", typeof(string));
        _with1.Add("AccountDisabled", typeof(bool));
 using (DirectoryEntry rootEntry = new DirectoryEntry(LDAPPath, LDAPUser, LDAPPassword))
        {
            using (DirectorySearcher searcher = new DirectorySearcher(rootEntry))
            {
            searcher.Filter = string.Format("(&(ObjectClass=Group)(CN={0}))", groupName);
            SearchResult result = searcher.FindOne();
            object members = result.GetDirectoryEntry().Invoke("Members", null);
            //<<< Get members

            //<<< loop through members
            foreach (object member in (IEnumerable)members)
            {
                DirectoryEntry currentMember = new DirectoryEntry(member);
                //<<< Get directoryentry for user
                if (currentMember.SchemaClassName.ToLower() == "user")
                {
                    System.DirectoryServices.PropertyCollection props1 = currentMember.Properties;
                    dt.Rows.Add(props1["sAMAccountName"].Value, props1["givenName"].Value, props1["sn"].Value, props1["displayName"].Value, props1["mail"].Value, Convert.ToBoolean(currentMember.InvokeGet("AccountDisabled")));
                }

            }
DataTable dt=新的DataTable(groupName);
var _,1=dt.列;
_加上(“AccountID”,typeof(string));
_加上(“名字”,类型(字符串));
_加上(“LastName”,typeof(string));
_加上(DisplayName),typeof(string));
_随附1.添加(“电子邮件”,类型为(字符串));
_加上1.添加(“AccountDisabled”,typeof(bool));
使用(DirectoryEntry rootEntry=newdirectoryEntry(LDAPPath、LDAPUser、LDAPPassword))
{
使用(DirectorySearcher search=新DirectorySearcher(rootEntry))
{
searcher.Filter=string.Format((&(ObjectClass=Group)(CN={0})),groupName);
SearchResult=searcher.FindOne();
对象成员=result.GetDirectoryEntry().Invoke(“成员”,null);

// 这个代码对我来说很好用

 DataTable dt = new DataTable(groupName);
        var _with1 = dt.Columns;
        _with1.Add("AccountID", typeof(string));
        _with1.Add("FirstName", typeof(string));
        _with1.Add("LastName", typeof(string));
        _with1.Add("DisplayName", typeof(string));
        _with1.Add("Email", typeof(string));
        _with1.Add("AccountDisabled", typeof(bool));
        _with1.Add("Groups", typeof(string));

        using (DirectoryEntry rootEntry = new DirectoryEntry(LDAPPath, LDAPUser, LDAPPassword))
        {
            using (DirectorySearcher searcher = new DirectorySearcher(rootEntry))
            {
            searcher.Filter = string.Format("(&(ObjectClass=Group)(CN={0}))", groupName);
            SearchResult result = searcher.FindOne();
            object members = result.GetDirectoryEntry().Invoke("Members", null);
            //<<< Get members

            //<<< loop through members
            foreach (object member in (IEnumerable)members)
            {
                DirectoryEntry currentMember = new DirectoryEntry(member);
                //<<< Get directoryentry for user
                if (currentMember.SchemaClassName.ToLower() == "user")
                {
                    System.DirectoryServices.PropertyCollection props1 = currentMember.Properties;
                    dt.Rows.Add(props1["sAMAccountName"].Value, props1["givenName"].Value, props1["sn"].Value, props1["displayName"].Value, props1["mail"].Value, Convert.ToBoolean(currentMember.InvokeGet("AccountDisabled")),"");
                }
                else if (currentMember.SchemaClassName.ToLower() == "group")
                {
                    System.DirectoryServices.PropertyCollection props1 = currentMember.Properties;
                    //foreach (var group in result.Properties["member"])
                    //{
                        dt.Rows.Add("","","","","",false,props1["name"].Value);
                    //}
                }
            }
   }
DataTable dt=新的DataTable(groupName);
var _,1=dt.列;
_加上(“AccountID”,typeof(string));
_加上(“名字”,类型(字符串));
_加上(“LastName”,typeof(string));
_加上(DisplayName),typeof(string));
_随附1.添加(“电子邮件”,类型为(字符串));
_加上1.添加(“AccountDisabled”,typeof(bool));
_添加(“组”,类型(字符串));
使用(DirectoryEntry rootEntry=newdirectoryEntry(LDAPPath、LDAPUser、LDAPPassword))
{
使用(DirectorySearcher search=新DirectorySearcher(rootEntry))
{
searcher.Filter=string.Format((&(ObjectClass=Group)(CN={0})),groupName);
SearchResult=searcher.FindOne();
对象成员=result.GetDirectoryEntry().Invoke(“成员”,null);
//