Tag Archives: AD

Obtain List of Active Directory Users Sorted by Last Logon Date

A common question asked by many HR Managers and Administrators a like.

How many users do we have in a company? and when did they last logon?

This quick one line will achieve this goal and send the output to a CSV file, which can be used to create reports in Microsoft Excel.

$adaccount = Get-ADUser -Filter * -Properties LastLogonDate,PasswordLastSet, whencreated |Where-Object {$_.enabled -eq $true} |Sort-Object -Property LastLogonDate -Descending |select Name, LastLogonDate, PasswordLastSet, Enabled, WhenCreated
$adaccount | export-csv ("C:\UserLastLogonDateV1.1.csv") -NoTypeInformation