Dump User and Password Age via Powershell to csv

Sometimes you just need to get a list of all your users and the last time they set their passwords. This is a pretty quick and dirty way to do it.

$reportObject = @()
$userList = Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq  $False} -Properties "DisplayName", "LastLogonTimeStamp", "LastLogonDate", "PasswordLastSet", "msDS-UserPasswordExpiryTimeComputed" |  Where-Object {$_.DisplayName -ne $null}
$userList | %{

    $output = "" | Select DisplayName, passwordlastset, ExpiryDate, LastLogonDate
    $output.DisplayName = $_.DisplayName
    $output.passwordlastset = $_.passwordlastset
    $output.ExpiryDate = ([datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime
    $output.LastLogonDate = $_.LastLogonDate
    $reportObject += $output
    $output | fl *

$reportObject | Convertto-CSV -NoTypeInformation
$reportObject | export-csv -Path c:\temp\UserPasswordAgeInfo.csv -NoTypeInformation

Leave a Reply

Your email address will not be published. Required fields are marked *