2011-07-13 32 views

答えて

14

戻す属性のリストで唯一の値として「*」を指定します。

操作属性を追加する場合は、リストに「+」を追加します。

+0

ありがとうございました。 search.PropertiesToLoad.Add( "*"); search.PropertiesToLoad.Add( "+"); – DFTR

2

DirectoryEntryを使用してプロパティのリストを生成することができます。それぞれのプロパティを使用してプロパティのリストを調べる必要があります。

DirectoryEntry objADAM = default(DirectoryEntry); 
    string properties = string.Empty; 
    foreach (string property in objADAM.Properties.PropertyNames) 
    { 
     properties += property + ", "; 
    } 

それはC#とActive Directoryに来るときはいつもしかし http://www.codeproject.com/KB/system/everythingInAD.aspx を参照することができます。

UPDATE:http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C

+3

はい - ただし、** only **は、その特定の 'DirectoryEntry'の値が割り当てられているプロパティを取得します。これは可能なプロパティのリスト全体を列挙しません** –

+0

'http:// www.codeproject.com/KB/system/everythingInAD.aspx'が見つかりません – Kiquenet

3

まあ限りDirectoryがあるとして懸念は意味がない、一人で "すべての属性をretreiving"。 あなたが意味するか:

  1. すべてのユーザー彼らはSCHEMA
  2. にすべてのユーザーおよび操作属性

  • 大切すべてのユーザー属性をdiscribedていると私は世話をしていないよう可能な属性いくつかのユーザーの属性は読み取り専用で、その他の属性は特定の値でのみ書き込むことができます。私はコンテンツを取得する方法を追加します。

    @Ghostfireは、評価されたすべてのユーザー属性と操作属性を回収するソリューションを提供します。

    DirectoryEntry deUser = new DirectoryEntry("LDAP://WM2008R2ENT:389/CN=AUser,OU=MonOu,DC=dom,DC=fr"); 
    
    
    foreach (string property in deUser.Properties.PropertyNames) 
    { 
        Console.WriteLine("\t{0} : {1} ", property, deUser.Properties[property][0]); 
    } 
    

    しかし、LDAP検索では、最良の方法は、あなたが盗んたいattributsを与えることであることを忘れないでください:

    /* Connection to Active Directory 
    */ 
    DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr"); 
    
    /* Directory Search 
    */ 
    DirectorySearcher dsLookFor = new DirectorySearcher(deBase); 
    dsLookFor.Filter = "(sn=users)"; 
    dsLookFor.SearchScope = SearchScope.Subtree; 
    dsLookFor.PropertiesToLoad.Add("cn"); 
    dsLookFor.PropertiesToLoad.Add("givenName"); 
    dsLookFor.PropertiesToLoad.Add("telephoneNumber"); 
    
    dsLookFor.Sort = new SortOption("givenName", SortDirection.Descending); 
    dsLookFor.VirtualListView = new DirectoryVirtualListView(1, 0, 2); 
    SearchResultCollection srcUsers = dsLookFor.FindAll(); 
    
  • 20

    私はすべてのパラメータの私のDirectoryEntryクラスのオブジェクトのリストをつかみます。私はそれに役立つことを願っています:

    objectClass = System.Object[] 
    cn = Administrator 
    sn = Kwiatek (Last name) 
    c = PL (Country Code) 
    l = Warszawa (City) 
    st = Mazowieckie (Voivodeship) 
    title = .NET Developer 
    description = Built-in account for administering the computer/domain 
    postalCode = 00-000 
    postOfficeBox = Warszawa Ursynów 
    physicalDeliveryOfficeName = Wojskowa Akademia Techniczna 
    givenName = Piotr (First name) 
    distinguishedName = CN=Administrator,CN=Users,DC=helpdesk,DC=wat,DC=edu 
    instanceType = 4 
    whenCreated = 2012-11-23 06:09:28 
    whenChanged = 2013-02-23 13:24:41 
    displayName = Piotr Kwiatek (Konto administratora) 
    uSNCreated = System.__ComObject 
    memberOf = System.Object[] 
    uSNChanged = System.__ComObject 
    co = Poland 
    company = HELPDESK 
    streetAddress = Kaliskiego 2 
    wWWHomePage = http://www.piotr.kwiatek.org 
    name = Administrator 
    objectGUID = System.Byte[] 
    userAccountControl = 512 
    badPwdCount = 0 
    codePage = 0 
    countryCode = 616 
    badPasswordTime = System.__ComObject 
    lastLogoff = System.__ComObject 
    lastLogon = System.__ComObject 
    logonHours = System.Byte[] 
    pwdLastSet = System.__ComObject 
    primaryGroupID = 513 
    objectSid = System.Byte[] 
    adminCount = 1 
    accountExpires = System.__ComObject 
    logonCount = 178 
    sAMAccountName = Administrator 
    sAMAccountType = 805306368 
    objectCategory = CN=Person,CN=Schema,CN=Configuration,DC=helpdesk,DC=wat,DC=edu 
    isCriticalSystemObject = True 
    dSCorePropagationData = System.Object[] 
    lastLogonTimestamp = System.__ComObject 
    mail = [email protected] 
    nTSecurityDescriptor = System.__ComObject 
    

    そしてここであなたがコードを持っている:あなたが指定したオブジェクトクラスのスキーマを照会見なければならないすべての可能なプロパティのリストについては

    string currentUserSid = WindowsIdentity.GetCurrent().User.Value; 
    
          PrincipalContext ctx = new PrincipalContext(
           ContextType.Domain, 
           "helpdesk.wat.edu"); 
    
          UserPrincipal up = UserPrincipal.FindByIdentity(
           ctx, IdentityType.Sid, 
           currentUserSid); 
    
          /* 
          * 
          */ 
          DirectoryEntry entry = up.GetUnderlyingObject() as DirectoryEntry; 
          PropertyCollection props = entry.Properties; 
    
          /* 
          * 
          */ 
          foreach (string propName in props.PropertyNames) 
          { 
           if (entry.Properties[propName].Value != null) 
           { 
            Console.WriteLine(propName + " = " + entry.Properties[propName].Value.ToString()); 
           } 
           else 
           { 
            Console.WriteLine(propName + " = NULL"); 
           } 
          } 
    
    
          Console.ReadKey(); 
    
    +1

    システムの値を取得する方法。 Object [] '、' System .__ ComObject'、 'System.Byte []'など***プロパティ***? – Kiquenet

    4
    // This will list ALL the properties from AD (between 200 and 800..or more) 
        // If someone has a solution for non AD servers please post it! 
    
        List<String> properties = new List<String>(); 
        IPAddress[] ips = Dns.GetHostAddresses(Server).Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray(); 
        if (ips.Length > 0) 
        { 
         DirectoryContext directoryContext = new DirectoryContext(DirectoryContextType.DirectoryServer, ips[0].ToString() + ":389", Username, Password); 
         ActiveDirectorySchema adschema = ActiveDirectorySchema.GetSchema(directoryContext); 
         ActiveDirectorySchemaClass adschemaclass = adschema.FindClass("User"); 
    
         // Read the OptionalProperties & MandatoryProperties 
         ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties(); 
    
         foreach (ActiveDirectorySchemaProperty schemaProperty in propcol) 
          properties.Add(schemaProperty.Name.ToLower()); 
        } 
    
    +0

    *** DirectoryContextの***ネームスペース***? – Kiquenet

    +0

    using System.DirectoryServices.ActiveDirectory; –

    0

    を。

    関連する問題