How to generate and export every user's last logon report 

The following is a comparison between obtaining an AD user's last logon report with Windows PowerShell and ADManager Plus:

Windows PowerShell

Steps to obtain every user's last logon date using PowerShell:

  • Identify the domain from which you want to retrieve the report.
  • Identify the LDAP attributes you need to fetch the report.
  • Identify the primary DC to retrieve the report.
  • Compile the script. 
  • Execute it in Windows PowerShell.
  • The report will be exported in the given format.
  • To obtain the report in a different format, modify the script accordingly to the needs of the user.

Sample Windows PowerShell script

Import-Module ActiveDirectory
function Get-ADUsersLastLogon()
$dcs = Get-ADDomainController 
-Filter {Name -like "*"} $users = Get-ADUser -LDAPFilter
"(&(objectCategory=person)(objectClass=user))" $time = 0 $exportFilePath = "c:\scripts\lastLogon.csv" $columns = "name,username,datetime" Out-File -filepath $exportFilePath
-force -InputObject $columns foreach($user in $users) { foreach($dc in $dcs) {  $hostname = $dc.HostName $currentUser =
Get-ADUser $user.SamAccountName |
Get-ADObject -Server $hostname
-Properties lastLogon if($currentUser.LastLogon -gt $time)  { $time = $currentUser.LastLogon } } if($time -eq 0){ $row = $user.Name+","+$user.SamAccountName+",Never" } else { $dt = [DateTime]::FromFileTime($time) $row = $user.Name+","+$user.SamAccountName+","+$dt } Out-File -filepath $exportFilePath -append -noclobber
-InputObject $row $time = 0 } } Get-ADUsersLastLogon
Click to copy entire script

ADManager Plus

To obtain the report,

  • Select Real Last Logon from the User Reports tab. 
  • Select the domain and OU. Click Generate. 
  • Select Export as to export the report in any of the preferred formats (CSV, PDF, HTML, CSVDE and XLSX).


A screenshot of ADManager Plus with last logon time stamp of all the users in AD

» Start 30-day Free Trial

Following are the limitations to obtain report of every user's last logon date using native tools like Windows PowerShell:

  • We can run this script only from the computers which has Active Directory Domain Services role.
  • Difficult to change date formats.
  • Difficult to apply different time zones on the date results.
  • Difficulty in exporting the report in other formats.
  • Applying more filters, like OU or 'User name starts with' will increase the LDAP query complexity

ADManager Plus will generate the report by automatically scanning all DCs in the domain to retrieve the last logon date of the users with the most recent timestamp in a simple and intuitively designed UI.

Find logon information on Active Directory users from prebuilt reports.

  Get 30-day free trial.
  • Embark on your script-free AD management, reporting, and automation journey with ADManager Plus.
  • By clicking 'Start your free trial now', you agree to processing of personal data according to the Privacy Policy.
  • Thanks
  • Your download should begin automatically in 15 seconds. If not, click here to download manually.

Related Powershell How-to Guides:

Email Download Link