Powershell, Guide, Microsoft

Powershell – Export Active Directory User Last logged on information to CSV

Last updated on March 19th, 2023 at 04:51 pm

Read Time:54 Second

If you want to export all your Active Directory users last logged on information, you can carry this out using Powershell and then exporting to CSV format.


First of all, you will need to import the ActiveDirectory module if you have not already done so. To do this, just open up a Powershell command box and run the following script:

Import-Module ActiveDirectory

Once this has completed, you can now add the below script into a PS1 file or use PowerShell ISE to run it:

Get-ADUser -Filter * -SearchBase "DC=techygeekshome,DC=info" -ResultPageSize 0 -Property CN, Description, LastLogonTimestamp |
Select-Object -Property CN, Description, @{ n = "LastLogonDate"; e = { [datetime]::FromFileTime( $_.lastLogonTimestamp ) } } |
Sort-Object -Property CN, Description, LastLogonDate |
Export-CSV -NoTypeInformation "C:\TGH\lastlogon.csv"

This will then export to CSV file where you enter the location at the end of the script.


If you have any questions or feedback on this post then please feel free to leave us a message below using our comments section and we will get back to you as soon as we can.

Click to rate this post!
[Total: 0 Average: 0]
Avatar for Andrew Armstrong

About Post Author

Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 23 years. Sharing experience and knowledge whenever possible! Making IT Happen.

Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us



Top Downloads


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 543 other subscribers.