尝试在System.DirectoryServices.AccountManagement中搜索以查找具有寻呼机字段的AD用户包含字符串

时间:2018-03-08 15:58:42

标签: c# .net active-directory

我尝试使用c#中的1234库进行搜索。目标是找到一个AD用户,其中包含一个包含字符串的寻呼机字段。

例如,如果我有position: fixed; bottom: 0; ,我需要找到一个用户的寻呼机字段包含" inputtxt=open("stuff.txt", "r") outputtxt=open("output.txt", "w") output="""""" for i in inputtxt.readlines(): nums=[] name="" for k in i: try: nums.append(int(k)) except: if k!=" ": name+=k avrg=0 for j in nums: avrg+=j avrg/=len(nums) line=name+" "+str(avrg)+"\n" output+=line outputtxt.write(output) inputtxt.close() outputtxt.close() "。

我无法弄清楚如何在s.ds.am中搜索寻呼机字段的内容以包含字符串。

2 个答案:

答案 0 :(得分:1)

使用*字符作为通配符。例如,在DirectoryEntry的过滤条件中,您可以使用以下内容:

<script type="text/javascript"> 
document.observe("dom:loaded", function() {

new Ajax.JSONRequest('http://www.abcd.com/ezzoom/hole/fill', {
    parameters: {isAjax: true,
             id:    '1090382',
             key:   'eJw1ybESgjAQhOFcJ5IlcXgDLSyU1rFxzlxchBsIYS6HBU8vjtrt/y3SZGAy8nB+73ztGgxKS1nmToljFXL6QSG8SLHmTTg+aRkND7JeP/Afu1wi01AQolKS8K2qtzRi7aJhhgOLgkrAKEkM3iFljuhUGFk5KuZcXMQkTwi0/XWDW9ue76fL4Xh9A5CyPlI=',
             holes: 'eJx1UsFKAzEQ/Zcc9lR3bUWUwlwiXCJFL1rQehBXQppMN6HZnWWStRTx351sra2gp8x7eZmZvJkPYdFDENMP8e5gA+Y4EtcP84eX+/nzk7w8F58j0WJ0eqf+CUXtcam83BMs09h0iiDJfkKhVVQe67wjNL2O+fdNHpyBpaL0roEQVL3Lf4j3BfbMqIZ4S9h3YO5i48Xh3YTF/6k4fYfep9S7U5CrbcwH8Mm3PSXSxthNq6IqNptNvibVhz6o1GtVLFW0hMfRSXDtOlSFBlKN0zuYWy531ZXjzDgqVdCZd42L5WScNWigrMmZDMlcMJUdBhcdthl7U05Oz/krWmkLcg1b6doViukrO0hQFYG/xcpBMfj4i7Kg19jHA/c2Ela1ZpjsqzCwUr2PrHxazB9n8oAXd7P7mVxcEbYRWiODa7ANFrsjyXc9yVwn1EhbmbbjL96rLRCvzUjcXFwvZrfzxxd5dpGEfYjYXDBJVtdgJDea+tNcXJNwGAgbxdazVawezGI0GafBsmFpAdgyRoNpDPe28di+XDDTxPh6'
    },
    onComplete: function(transport) {
        var json = transport.responseJSON;

                    for(var i=0;i<json.fill.length;i++){
                      var obj = json.fill[i];
                       $('ezzoom-'+obj.block).update(obj.data);
                    }

                    if (json.conversionRate) 
            convertFromJson(json);
    }
  });
});
</script>

https://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx

https://msdn.microsoft.com/en-us/library/ms679102(v=vs.85).aspx

另外,小心使用S.DS.AM.我知道它提供了许多有用的功能,但它比S.DS.AD慢得多。

Active Directory: The Principal Class - S.DS.AM vs S.DS.AD

<强>更新 请记住,Microsoft在S.DS.AM命名空间包装器中引入了以下类:

  1. UserPrincipal
  2. ComputerPrincipal
  3. GroupPrincipal
  4. https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.principal.aspx

    研究继承层次结构并检查可用的属性/属性 -  WYSWIG。如果未包含您要搜索的属性,则无法使用S.DS.AM - 您将需要使用S.DS.AD.

    在搜索Principal类中包含特定字符串时可用的属性时,*通配符仍然存在。

    搜索S.DS.AM中的可用属性时的有用帖子:search by samaccountname with wildcards

    更新2:

    我在SO上发布了以下帖子,可能对您要执行的操作有用:How to get Active Directory Attributes not represented by the UserPrincipal class

答案 1 :(得分:1)

如果您想试验S.DS.AM,请尝试使用此方法。在return listPrincipal行放置一个断点,并检查每个主要变量中包含的内容。

private static List<Principal> GetPrincipalList (string strPropertyValue, string strDomainController)
        {
            List<Principal> listPrincipal = null;
            Principal principal = null;
            GroupPrincipal groupPrincipal = null;
            UserPrincipal userPrincipal = null;
            ComputerPrincipal computerPrincipal = null;
            PrincipalSearchResult<Principal> listPrincipalSearchResult = null; // Groups
            PrincipalContext principalContext = null;
            ContextType contextType;
            IdentityType identityType;

            try
            {
                // Setup a UserPrincipal list.
                listPrincipal = new List<Principal>();

                // Set the contextType to Domain because we are going through the AD directory store.
                contextType = ContextType.Domain;

                // Setup a domain context.
                principalContext = new PrincipalContext(contextType, strDomainController);

                // Setup the IdentityType. This is required, otherwise you will get a MultipleMatchesException error that says "Multiple principals contain a matching Identity."
                // This happens when you have two objects that AD thinks match whatever you're passing to UserPrincipal.FindByIdentity(principalContextDomain, strPropertyValue)
                // Use IdentityType.Guid because GUID is unique and never changes for a given object.                   
                identityType = IdentityType.Guid;

                // Find user.
                principal = Principal.FindByIdentity(principalContext, identityType, strPropertyValue);
                groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, identityType, strPropertyValue);
                userPrincipal = UserPrincipal.FindByIdentity(principalContext, identityType, strPropertyValue);
                computerPrincipal = ComputerPrincipal.FindByIdentity(principalContext, identityType, strPropertyValue);

                // Return the listPrincipal list.
                return listPrincipal;
            }
            finally
            {
                // Cleanup objects.
                listPrincipal = null;
                listPrincipalSearchResult = null;
                principalContext = null;
                groupPrincipal = null;
                userPrincipal = null;
                computerPrincipal = null;
            }
        }