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-10) Interesting Attribute: Determining Password Expiration Date (msDS-UserPasswordExpiryTimeComputed)

Posted by Jorge on 2014-08-10


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

$userInfo = @() Import-Module ActiveDirectory Get-ADuser -Filter * | %{ $sAMAccountName = $null $sAMAccountName = $_.sAMAccountName $pwdExpire = $null $pwdExpire = (Get-ADuser $sAMAccountName -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed" If ($pwdExpire -ne 9223372036854775807){ $pwdExpire = Get-Date -Date ([DateTime]::FromFileTime([Int64]::Parse($pwdExpire))) -Format "yyyy-MM-dd HH:mm:ss" } Else { $pwdExpire = "PWD Never Expires" } $userInfoEntry = "" | Select "Logon Account","Pwd Expire" $userInfoEntry."Logon Account" = $sAMAccountName $userInfoEntry."Pwd Expire" = $pwdExpire $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: ms-DS-User-Password-Expiry-Time-Computed attribute

MSDN: 3.1.1.4.5.33 msDS-UserPasswordExpiryTimeComputed

MSDN: 2.461 Attribute msDS-UserPasswordExpiryTimeComputed

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: