Use powershell to get user last password changed time

By Ramu Soft

This explains how to get user last password changed time from active directory. Based on this information we can alert users to change the password if they haven't done it for long time. Also we can use this code while troubleshooting problems related to password changes.

$user = "user1"
$searcher=New-Object DirectoryServices.DirectorySearcher
$searcher.Filter="(&(samaccountname=$user))"
$results=$searcher.findone()
$changedtime = [datetime]::fromfiletime($results.properties.pwdlastset[0])
write-host -b blue -f red The user, $user has changed password last time at $changedtime

In the above code snippet "User1" is the name of the user for whom we are trying to find last password changed time.

Hope this hellps.

Use powershell to get user last password changed time  (3874 Views)