当创建一个新用户对象时,在Active Directory中将其存储为whenCreated属性。该属性指定了创建用户对象的日期和时间,以UTC格式表示。以下是使用C#代码示例获取用户对象的whenCreated属性的方法:
using System;
using System.DirectoryServices;
namespace ActiveDirectoryExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // AD User to retrieve whenCreated for
            string userName = "testuser";
            // Setup Directory Entry and Searcher
            DirectoryEntry entry = new DirectoryEntry("LDAP://DC=domain,DC=com");
            DirectorySearcher searcher = new DirectorySearcher(entry);
            // Search for User
            searcher.Filter = $"(samaccountname={userName})";
            SearchResult result = searcher.FindOne();
            if (result != null)
            {
                // Get whenCreated attribute
                string whenCreated = result.Properties["whenCreated"][0].ToString();
                Console.WriteLine($"User {userName} was created on {whenCreated}");
            }
            else
            {
                Console.WriteLine($"User {userName} not found");
            }
        }
    }
}
请注意替换LDAP路径和域以匹配你的环境,并更改userName变量以获取所需的用户的whenCreated属性。