Найдите недавно созданных пользователей Active Directory на C#.C#

Место общения программистов C#
Anonymous
Найдите недавно созданных пользователей Active Directory на C#.

Сообщение Anonymous »

Я использую этот PowerShell для получения информации о пользователях, созданных за последние 24 часа, из Active Directory:
$ous = 'OU=test,DC=test,DC=local' $When = ((Get-Date).AddDays(-1)).Date $ous | ForEach { Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated,* -SearchBase $_ }";

Как получить тот же результат, используя C#?
Вот мой код C#:
static void Main(string[] args)
{
// LDAP string to define your OU
string ou = "OU=test,DC=test,DC=local";

// set up a "PrincipalContext" for that OU
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "test.local", ou))
{
// define the "query-by-example" user (or group, or computer) for your search
UserPrincipal qbeUser = new UserPrincipal(ctx);

// set whatever attributes you want to limit your search for, e.g. Name, etc.
qbeUser.Surname = "ilgezdi";

// define a searcher for that context and that query-by-example
using (PrincipalSearcher searcher = new PrincipalSearcher(qbeUser))
{
foreach (Principal p in searcher.FindAll())
{
// Convert the "generic" Principal to a UserPrincipal
UserPrincipal user = p as UserPrincipal;

if (user != null)
{
console.Write(user);
}
}
}
}
}

Вернуться в «C#»