Michael Kullish in our environment, this script only finds and logs couple users, and then prints out errors:
Get-AduserResultantPasswordPolicy : Cannot find an object with identity: [name of one FPG policy]
I figured out that piping anything to where will cause only few object to be found for some reason.
get-aduser -filter * -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress | where {$_.Enabled -eq "True"} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false }
Altering the line to:
get-aduser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and passwordexpired -eq $False} -properties Name, PasswordNeverExpires, PasswordExpired, PasswordLastSet, EmailAddress
Will bring up right results, but cause the script to write empty log and give error Failed to aquire token