Jorge's Quest For Knowledge!

All You Need To Know About Identity And Security On-Premises And In The Cloud. It's Just Like An Addiction, The More You Have, The More You Want To Have!

(2014-08-06) Interesting Attribute: Determining Password Last Set (pwdLastSet)

Posted by Jorge on 2014-08-06


Have you ever wanted to get a simple list of all user accounts and see when their password was last set? Well, you can use the PowerShell script below if you want.

$userInfo = @() Import-Module ActiveDirectory Get-ADuser -Filter * -Properties pwdLastSet | %{ $sAMAccountName = $null $sAMAccountName = $_.sAMAccountName $pwdLastSet = $null $pwdLastSet = $_.pwdLastSet If ($pwdLastSet -ne 0){ $pwdLastSet = Get-Date -Date ([DateTime]::FromFileTime([Int64]::Parse($pwdLastSet))) -Format "yyyy-MM-dd HH:mm:ss" } Else { $pwdLastSet = "PWD Never Set" } $userInfoEntry = "" | Select "Logon Account","Pwd Last Set" $userInfoEntry."Logon Account" = $sAMAccountName $userInfoEntry."Pwd Last Set" = $pwdLastSet $userInfo += $userInfoEntry } Clear-Host $userInfo | FT -AutoSize

Oh, you wanted to export that info to a CSV instead of the screen output? Replace the last line "$userInfo | FT -AutoSize" with "$userInfo | Export-Csv <Path to CSV> -NoTypeInformation"

image

Figure 1: Output Of PowerShell Script

MSDN: Pwd-Last-Set attribute

Cheers,

Jorge

———————————————————————————————

* This posting is provided "AS IS" with no warranties and confers no rights!

* Always evaluate/test yourself before using/implementing this!

* DISCLAIMER: https://jorgequestforknowledge.wordpress.com/disclaimer/

———————————————————————————————

############### Jorge’s Quest For Knowledge #############

######### http://JorgeQuestForKnowledge.wordpress.com/ ########

———————————————————————————————

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: