Tag: active directory

从多个林环境中获取Domain Local Group的所有成员

我有一个域本地组,它是林A中域A的一部分。 我试图迭代这个组中的所有成员。 它迭代遍历林A的所有域,但不会迭代域B中的任何组成员,在林B中。 是从不同的森林开始迭代相同代码的唯一方法吗? 我们已尝试使用System.DirectoryServices.AccountManagement类,但它们和Windows Server 2012域控制器似乎存在问题。 private List getUsersInGroup(string groupDN) { var users = new List(); using (DirectoryEntry de = new DirectoryEntry(“GC://rootDSE”)) { var rootName = de.Properties[“rootDomainNamingContext”].Value.ToString(); using (var userBinding = new DirectoryEntry(“GC://” + rootName)) { using (DirectorySearcher adSearch = new DirectorySearcher(userBinding)) { adSearch.ReferralChasing = ReferralChasingOption.All; adSearch.Filter = String.Format(“(&(memberOf={0})(objectClass=person))”, groupDN); adSearch.PropertiesToLoad.Add(“distinguishedName”); adSearch.PropertiesToLoad.Add(“givenname”); adSearch.PropertiesToLoad.Add(“samaccountname”); adSearch.PropertiesToLoad.Add(“sn”); […]

WCF服务中的System.DirectoryServices.AccountManagement.PrincipalContext和Impersonation

在位于WCF服务后面的代码中使用PrincipalContext 。 WCF服务正在模拟,以允许“传递”类型身份validation。 虽然我使用Active Directory(主要是System.DirectoryServices.Protocols命名空间)所做的其他事情在这种情况下工作正常,但由于某种原因,System.DirectoryServices.AccountManagement中的类会使用。 失败的示例代码: PrincipalContext context = new PrincipalContext(ContextType.Domain, domainName); UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, UserName); 当我调用FindByIdentity ,我得到一个COMException:“发生了一个操作错误”。 对PrincipalContext调用也会失败,例如: string server = context.ConnectedServer; OperationContext.Current.ServiceSecurityContext和Thread.CurrentPrincipal.Identity显示模拟正常工作。 并且,就像我说的那样,S.DS.P中的其他AD任务工作正常。 如果我在PrincipalContext上显式设置凭据,一切正常。 例如: PrincipalContext context = new PrincipalContext(ContextType.Domain, domainName, user, password); UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, UserName); 现在一切正常。 但我不知道来电者的用户名和密码; 我必须依靠冒充。 关于什么会引起我所看到的问题的任何想法? 提前致谢! 詹姆士

在Visual Studio中运行PowerShell脚本时无法获取Active Directory终端服务属性

我遇到了一个奇怪的问题,也许有人可以帮助我。 我试图在使用Windows 10的计算机上使用C#从Active Directory用户检索终端服务属性。我这样做是通过在我的应用程序中运行PowerShell脚本,如下所示: var script = $@”Import-module ActiveDirectory $user=[ADSI]””LDAP://192.111.222.33:389/CN=SomePerson,DC=Domain,DC=local”” $user.psbase.Username = “”administrator”” $user.psbase.Password = “”adminPassword”” $user.psbase.invokeget(“”TerminalServicesProfilePath””)”; using (var runspace = RunspaceFactory.CreateRunspace()) { runspace.Open(); using (var pipeline = runspace.CreatePipeline()) { pipeline.Commands.AddScript(script); var test = pipeline.Invoke(); Console.WriteLine(“Success: “); return true; } } 我得到这个例外: System.Management.Automation.MethodInvocationException:’exception调用“InvokeGet”带有“1”参数:“未知名称。(HRESULTexception:0x80020006(DISP_E_UNKNOWNNAME))”’ 当我在使用Windows Server 2012作为操作系统的计算机上运行Visual Studio 2015中的上述代码时,它工作正常! 我确保我的Windows 10机器也安装了RSAT。 奇怪的是,当我从Windows 10机器上的PowerShell控制台运行脚本时,它可以工作! 以下是我的PowerShell脚本的确切代码: $user = […]

活动目录UserPrincipal.Current.GetGroups()返回本地而非Web服务器上的组

以下在我的本地开发框中非常有用。 但是,当我将其移动到Web服务器时,它会失败,甚至不会记录错误: public static List getAuthorizationGrps(string userName) { List grps = new List(); try { PrincipalSearchResult groups = UserPrincipal.Current.GetGroups(); IEnumerable groupNames = groups.Select(x => x.SamAccountName); foreach (var name in groupNames) { grps.Add(name.ToString()); } return grps; } catch (Exception ex) { Log.WriteLog(“Error in retriving form data: ” + ex.Message); } } 我是否必须在网络服务器上设置权限才能查询群组? 我可以让当前用户在本地和Web服务器上都没有问题。 任何想法都将不胜感激,我已经为此奋斗了2天。

调用commitChanges()在Active Directory中什么都不做?

尽管我使用了CommitChanges函数,但似乎在ActiveDirectory中没有保存更改。 我是否使用正确的方法来解决这个问题? //Test OU Group: OU=First Group,OU=Domain Users,DC=DOMAIN,DC=com String userName, password; Console.Write(“Username: “); userName = Console.ReadLine(); Console.Write(“Password: “); password = Console.ReadLine(); //ENTER AD user account validation code here String strLDAPpath = “LDAP://OU=First Group,OU=Domain Uers,DC=DOMAIN,DC=com”; DirectoryEntry entry = new DirectoryEntry(strLDAPpath,userName,password,AuthenticationTypes.Secure); //DirectoryEntry entry = new DirectoryEntry(strLDAPpath); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = “(ObjectCategory=user)”; foreach (SearchResult result […]

从AD获取扩展属性?

我是从我们的网络团队成员那里得到的: 您可以看到extensionAttribute2中有一个值。 如何检索此值 – 我无法在UserPrincipal对象中看到extensionAttributes – 除非我遗漏了某些内容。 我已经回到了一个级别并尝试了以下内容: UserPrincipal myUser = UserPrincipal.FindByIdentity(con, identityName); DirectoryEntry de = (myUser.GetUnderlyingObject() as DirectoryEntry); if (de != null) { // go for those attributes and do what you need to do if (de.Properties.Contains(“extensionAttribute2”)) { return de.Properties[“extensionAttribute2”][0].ToString(); } else { return string.Empty; } } 但是这不起作用 – 调试它有大约40个属性可用但extensionAttribute2没有

活动目录:获取用户所在的组

我想找到用户所在的组列表。 我从http://www.codeproject.com/KB/system/everythingInAD.aspx尝试了几个解决方案但没有结果。 这段代码给我一个“真实”,表示LDAP正在运行: public static bool Exists(string objectPath) { bool found = false; if (DirectoryEntry.Exists(“LDAP://” + objectPath)) found = true; return found; } 谢谢, 更新1: public ArrayList Groups(string userDn, bool recursive) { ArrayList groupMemberships = new ArrayList(); return AttributeValuesMultiString(“memberOf”, “LDAP-Server”, groupMemberships, recursive); } public ArrayList AttributeValuesMultiString(string attributeName, string objectDn, ArrayList valuesCollection, bool recursive) { DirectoryEntry […]

如何在Active Directory中更改用户的登录名

我想在Active Directory中更改用户的.NET应用程序登录。 我现在正以这种方式改变它: DirectoryEntry userToUpdate = updatedUser.GetDirectoryEntry(); userToUpdate.Properties[“sAMAccountName”].Value = user.NewLogin; userToUpdate.CommitChanges(); 但它并不像我预期的那样有效。 当我在为此用户检入AD“Active Directory用户和计算机”条目时,然后在“帐户”选项卡上,我看到: – “用户登录名”属性未更新 – “用户登录名(pre-Windows 2000)”属性已正确更新。 如何从C#代码正确更新AD中的登录名? 我应该在DirectoryEntry中设置什么属性,或者有另一种方法来更改登录名。

UserPrincipal.FindByIdentity()始终返回null

我正在使用LdapAuthentication将用户登录到Active Directory。 我想找到用户所属的所有组。 我使用以下代码: string adPath = “LDAP://OU=HR Controlled Users,OU=All Users,DC=myDomain,DC=local”; LdapAuthentication adAuth = new LdapAuthentication(adPath); try { if (true == adAuth.IsAuthenticated(“myDomain”, txtLoginEmail.Text, txtLoginPassword.Text)) { string email = txtLoginEmail.Text; using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) { UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.Name, email); foreach (var group in user.GetGroups()) { Console.WriteLine(group.Name); } } } } catch(Exception e) […]

检查Active Directory帐户是否已锁定(WPF C#)

大家好(这是我的第一篇文章)我有一些简单的AD代码,我从Codeplex中提取http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C )并且我能够从所述代码中获取所有最终用户的信息。 现在,我一直在搜索和搜索,并从这里找到一些有趣的代码片段,并在网络上关于“用户是否被锁定?” 我想使用我已经使用了2年的代码,只需添加一些内容就可以添加到锁定的部分…如果有一个文本框给了我,我会很高兴信息,或复选框,或只是说“用户锁定”的东西,然后我会通知我的Exchange团队并让用户解锁… 我的代码如下: string eid = this.tbEID.Text; string user = this.tbUserName.Text.ToString(); string path = “PP://dc=ds,dc=SorryCantTellYou,dc=com”; DirectoryEntry de = new DirectoryEntry(path); DirectorySearcher ds = new DirectorySearcher(de); ds.Filter = “(&(objectCategory=person)(sAMAccountName=” + eid + “))”; SearchResultCollection src = ds.FindAll(); //AD results if (src.Count > 0) { if (src[0].Properties.Contains(“displayName”)) { this.tbUserName.Text = src[0].Properties[“displayName”][0].ToString(); } } 所以,如果我可以弄清楚如何使用相同的目录条目,并且搜索者向我显示帐户锁定状态,这将是惊人的..请协助