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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s