Export Last Logon Time of All Active Directory (AD) Users using PowerShell Script
Table of Contents
Hi Guys…!!! In this post we are going to see how can we export last logon users from Active Directory by using PowerShell script.
This kind of information is required when we want to know how many users are not logged on from last some month or never logged on or when a particular user has logged on?
For single user we can see last logon time stamp in active directory.
Just open Active Directory Users and Computers and click on View and Select Advanced Features.
After that Select the user and open its properties. On that windows You will see Attribute Editor tab.
In that tab check for last logon time stamp as shown below.
Its easy to find single user’s last logon time, but for all AD users you have to go with PowerShell script.
Please refer below steps to perform export all AD users last logon time.
- Log in to ADDS server
- Open PowerShell ISE run as Administrator
- Type below given script as shown in screenshot.
4. Run the script.
5. Exported csv file is located in C: drive. You can change it as per your need.
Script:
“$Path = ‘C:\LastLogon.csv’ Get-ADUser -Filter {enabled -eq $true} -Properties LastLogonTimeStamp | Select-Object Name,@{Name=”Stamp”; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp).ToString(‘yyyy-MM-dd_hh:mm:ss’)}} | Export-Csv -Path $Path –notypeinformation”
After this when you open exported csv, it will look like.
Enjoy…!!!