Hi ,
The best thing to do in these cases is to clear the PowerShell session state before running the command, this way we make sure we always get the latest information from Active Directory. Here are some changes to your script for you to try and see if it solves your problem:
private void fillADUsers()
{
AdUsers = new Collection<PSObject>();
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddScript("Clear-Variable -Scope Global");
powershell.AddScript("Clear-Variable -Scope Local");
powershell.AddScript("Clear-Variable -Scope Script");
powershell.AddScript("Get-ADUser -Filter * -Properties LastLogon, whenCreated, Enabled, LockedOut");
try
{
AdUsers = powershell.Invoke();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}
}
Regards,