If you need to export the list of users in your Active Directory along with their last password reset or update date, here’s a simple PowerShell script that will help you achieve that. The script retrieves the PasswordLastSet
property for all users and exports the results into a CSV file for easy analysis.
PowerShell Script:
# Ensure the Active Directory module is loaded
Import-Module ActiveDirectory
# Define the path for the CSV file where the results will be saved
$csvFilePath = "C:\Users\LastPasswordReset.csv"
# Retrieve all users and export their DisplayName, SamAccountName, and PasswordLastSet
Get-ADUser -Filter * -Properties DisplayName, PasswordLastSet | Select-Object `
DisplayName, SamAccountName, PasswordLastSet | Sort-Object PasswordLastSet |
Export-Csv -Path $csvFilePath -NoTypeInformation
# Output the path of the CSV file
Write-Host "Exported results to $csvFilePath"

How the Script Works:
- Imports the Active Directory Module:
The script starts by ensuring that the Active Directory module is loaded into your PowerShell session. - Defines the Export Path:
The$csvFilePath
variable defines the location where the results will be saved. In this case, it saves to"C:\Users\LastPasswordReset.csv"
, but you can modify it as per your needs. - Retrieves Users’ Password Information:
The script fetches all users in Active Directory, along with theirDisplayName
,SamAccountName
(username), andPasswordLastSet
properties. - Sorts by Last Password Reset Date:
The users are sorted based on thePasswordLastSet
date to help identify when the last password reset took place. - Exports to CSV:
Finally, the results are exported to a CSV file, making it easier to analyze and share the data.
Sample Output:
After running the script, you’ll get a CSV file with the following format:
DisplayName | SamAccountName | PasswordLastSet |
---|---|---|
John Doe | johndoe | 2024-01-20 15:30:00 |
Jane Smith | janesmith | 2023-12-10 10:20:00 |
Michael Johnson | mjohnson | 2023-11-05 09:15:00 |
Running the Script:
- Save the Script: Save the script as a
.ps1
file (e.g.,Export-PasswordLastReset.ps1
). - Run PowerShell as Administrator: Ensure you have the necessary permissions to query Active Directory and run the script.
- Customize the File Path (Optional): You can modify the
$csvFilePath
variable to save the CSV file to a different location. - Execute the Script: Run the script, and the results will be saved in the defined path.
This script is a great way to quickly audit and review when users last changed their passwords, helping with compliance and security assessments.
Let me know if you have any questions or need further customization!
This can be posted as a helpful guide or a tutorial for others working with Active Directory and PowerShell