Get-ADUser -Filter * -SearchBase "CN=Users,DC=contoso,DC=com" -ResultPageSize 0 -Property CN, pwdLastSet |
Select-Object -Property CN, SamAccountName, @{ n = "PwdLastSetDate"; e = { [datetime]::FromFileTime( $_.pwdLastSet ) } } |
Sort-Object -Property PwdLastSetDate
Gets the Active Directory users in a given OU and sorts them by Password Last Set Date.
PS C:\> Get-ADUser -Filter * -SearchBase "CN=Users,DC=contoso,DC=com" -ResultPageSize 0 -Property CN, pwdLastSet | >> Select-Object -Property CN, SamAccountName, @{ n = "PwdLastSetDate"; e = { [datetime]::FromFileTime( $_.pwdLastSet ) } } | >> Sort-Object -Property PwdLastSetDate CN SamAccountName PwdLastSetDate -- -------------- -------------- Bill Bryson BBryson 11/27/2018 11:01:38 AM Mike Dexter MDexter 11/28/2018 8:47:44 PM Terry Pratchett TPratchett 3/30/2019 5:32:14 PM Bill Gates BGates 3/9/2019 1:43:33 PM Carl Sagan CSagan 3/21/2019 5:19:45 PM Carl S. Robot crobot 3/22/2019 6:37:02 AM Mike Ness mness 4/3/2019 3:41:06 PM