← script library
Generate a List of Active Directory Users and Their Last Logon Dates
Active DirectoryJanuary 5, 2025
Understanding user activity in Active Directory is key for maintaining security and compliance. This PowerShell script retrieves a list of active users along with their last logon dates. Administrators can use this information to identify inactive accounts and optimize their user management processes. At ServerEngine, we develop innovative solutions to enhance your IT management experience.
powershell
Import-Module ActiveDirectory
function Get-ADUserLogonInfo {
$users = Get-ADUser -Filter * -Properties LastLogonDate | Select-Object Name, LastLogonDate
return $users
}
$logonInfo = Get-ADUserLogonInfo
$logonInfo | Format-Table -AutoSize
$logonInfo | Export-Csv -Path "C:\Path\To\Your\ADUserLogonInfo.csv" -NoTypeInformationRun it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Active Directory
Active Directory User Onboarding with PowerShell
2026-08-17Active Directory User Offboarding with PowerShell
2026-08-17Disable an Active Directory User with PowerShell
2026-08-17Enable an Active Directory User with PowerShell
2026-08-17Unlock an Active Directory Account with PowerShell
2026-08-17Reset an Active Directory Password with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.