Monday, April 1, 2013

Script: Query AD for when users last changed their passwords

I ran into a challenging question today... My manager asked if I could get a report of all the users and when they changed their password. I knew I could get this via "DSGET and DSQUERY" but I wanted to force myself to use PowerShell. So here is the quick little script that I wrote that will do just that...

- You already have a TXT file on your computer that has a list of usernames for all the accounts
- You run these commands on a domain controller or a computer with the remote administration tools installed (to get the AD Module for PowerShell)

The Script:

Import-module activedirectory


Stop-Transcript | out-null

$ErrorActionPreference = "Continue"

Start-Transcript -path C:\output.txt -append

$list = get-content c:\<path to the TXT file with your users in it>\users.txt

Foreach ($username in $list) {get-aduser -id $username -Properties passwordlastset |select-object -property name,enabled,passwordlastset}


The "Start-Transcript" and "Stop-Transcript"enable you to get the output in a TXT file so you can import it in excel for later use and manipulation.

Good luck!!!

1 comment:


    please see my code also bro