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

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. Guide 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 […]

Powershell Export Active Directory User Last Logged On Information To

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.

Guide

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 been 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:TGHlastlogon.csv"

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

Feedback

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.

🛠️

Gear We Recommend

Testing configs is easier with a dedicated admin machine set up right. Here’s the kit we use.

Browse our Windows Admin Toolkit picks on Amazon

As an Amazon Associate, TechyGeeksHome earns from qualifying purchases.


Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Andrew Armstrong

Andrew Armstrong is a UK-based IT professional with 26+ years of hands-on experience in Windows, Windows Server, SCCM/ConfigMgr, Active Directory, PowerShell, and enterprise infrastructure.

He founded TechyGeeksHome in 2010 and has published over 1,500 practical guides covering real-world IT problems and solutions. When not solving IT problems,

Andrew develops free Windows utilities including Ultimate Settings Panel, which has been downloaded over 850,000 times.

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

  1. Is lastlogondate a relevant attribute?

    Wouldn’t outlook or email checking it appear as a last log on?

Comments are closed.