windows server 2016 identity group

谁都会走 提交于 2020-06-01 05:37:05

问题


I opened active directory users and computers, selected builtin and I created a group called Employee, and added my own current user to it. However when checking my groups in code like this I cannot see the Employee group

        WindowsIdentity identity = WindowsIdentity.GetCurrent();
        var myPrincipal = new WindowsPrincipal(identity);
        identity.Groups.Select(x => "NTAccounts - " + x.Translate(typeof(NTAccount)).ToString()

`

and this is all I get, am I doing something wrong ? all I need is to have a few groups with users I can work with..

appreciate your advice


回答1:


this code pulls information from active directory which is what I needed I just expected it to be at windows identity level, so my bad... resolved

using (var ctx = new PrincipalContext(ContextType.Domain, "your DC name"))
            {
                var myDomainUsers = new List<string>();
                var userPrinciple = new UserPrincipal(ctx);
                using (var search = new PrincipalSearcher(userPrinciple))
                {
                    foreach (var domainUser in search.FindAll())
                    {
                        if (domainUser.DisplayName != null)
                        {
                            groupNames.Add("domainUser displayName - " + domainUser.DisplayName);
                            groupNames.Add("domainUser getGroups - " + domainUser.GetGroups().Select(x => x.Name).ToList().Join(","));
                        }
                    }
                }
            }


来源:https://stackoverflow.com/questions/61938105/windows-server-2016-identity-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!