Random Project

PasswordExpired does not work properly

I tried this script with PasswordExpired and I found no result. When I ran:

Get-ADUser -Filter * -Property PasswordExpired | Where {$_.Enabled -eq ‘True’ -and $_.PasswordExpired -Eq ‘True’}

I do get 1 result. It seems Search-ADAccount and Get-ADUser are giving different results.

I tried to change the script:

if($action -eq “PasswordExpired”)
{
$command=”Get-ADUser -Filter * -Property PasswordExpired | Where {$_.Enabled -eq ‘True’ -and $_.PasswordExpired -Eq ‘True’}”
$result=invoke-expression $command
}
else
{
$command=”Search-ADAccount -“+$action+” -SearchBase ‘”+$searchBase+”‘ -SearchScope “+$searchScope
$result=invoke-expression $command
}

I did not get any result with this change. How can I get the correct response for PasswordExpired accounts?