Hi,
I looked at the code and corrected some small syntax erros and now it is working (you need to adjust the $searchbase and if you want - the path to the csv):
$verbosepreference = "continue"
$searchdate = '2020-07-02' #yyyy-MM-dd format
$searchbase = "OU=OU=365 - Insight Users,DC=Demo,DC=local"
$passwordsNotChangedSince = $([datetime]::parseexact($searchdate,'2020-07-02',$null)).ToFileTime()
write-verbose "Finding users whose passwords have not changed since $([datetime]::fromfiletimeUTC($passwordsNotChangedSince))"
Get-ADUser -filter { Enabled -eq $True } –Properties pwdLastSet -searchbase $searchbase | where { ($_.pwdLastSet -lt $passwordsNotChangedSince) -and ($_.pwdLastSet -ne 0)} | Select-Object name,sAmAccountName,@{Name="PasswordLastSet";Expression={
[datetime]::FromFileTimeUTC($_.pwdLastSet)
}
} | Export-Csv c:\temp\test1.csv
I hope I could help out.
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Best regards,
Stoyan