title: Get AD user creation date in C#
body: <p>I'm currently trying to get different info out of my AD.
  but I'm having some issues with pulling the creation date of my users.</p>
  
  <p>I get the correct date on some users, but on others I get null.</p>
  
  <p>My current code looks like so:</p>
  
  <pre><code>PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
  PrincipalSearchResult&lt;Principal&gt; rsc = srch.FindAll();
  foreach (Principal found in rsc)
  {    
      using (PrincipalContext ctx2 = new PrincipalContext(ContextType.Domain, "nianetas.local"))
      {
          UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, found.SamAccountName);
          DateTime creationTime;
          string creTime = found.GetProperty("whenCreated");
  
          if (!string.IsNullOrEmpty(creTime))
          {
              creationTime = DateTime.ParseExact(creTime,
                  "dd-MM-yyyy HH:mm:ss", null);
          }
          else
          {
              creationTime = DateTime.MinValue;
          }
      }
  }
  </code></pre>
  
  <p>GetProperty function:</p>
  
  <pre><code>public static String GetProperty(this Principal principal, String property)
  {
      DirectoryEntry directoryEntry = principal.GetUnderlyingObject() as DirectoryEntry;
      if (directoryEntry.Properties.Contains(property))
          return directoryEntry.Properties[property].Value.ToString();
      else
          return String.Empty;
  }
  </code></pre>