Using Powershell To Get User Last Logon Date

Share This:

As an Active Directory Administrator, determining the date that a user last logged onto the network could be important at some point. If you have access to the Attribute Editor in your Active Directory tools, you can look for the LastLogonDate attribute. The other option is to use Powershell, and there are two methods to access this information.

Using Get-ADUser

The first option basically gives you the same data that the Attribute Editor GUI would display. In Powershell, run this command to get the data you need, then scroll down the list and look for LastLogonDate.

Get-ADUser username -properties *

Powershell Script

The next method is to use the Powershell script below. Save this script as a .ps1 file and edit the username in the last line of the script (in bold below), then run it.

Import-Module ActiveDirectory

function Get-ADUserLastLogon([string]$userName)
$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
$hostname = $dc.HostName
$user = Get-ADUser $userName -Server $hostname | Get-ADObject -Properties lastLogon
if($user.LastLogon -gt $time)
$time = $user.LastLogon
$dt = [DateTime]::FromFileTime($time)
Write-Host $username "last logged on at:" $dt }

Get-ADUserLastLogon -UserName username

Share This:

Related Content


  1. Dave Smith March 20, 2019
    • asdasafas July 10, 2019
      • Robert Russell July 11, 2019
        • Adam August 7, 2019
  2. Curtis August 5, 2019
    • Adam August 7, 2019
      • Adam August 8, 2019
  3. Pingback: Active Directory Last Login Date July 14, 2020
  4. Pingback: Active Directory Last User Login July 14, 2020
  5. Pingback: Ad Computer Last Login July 19, 2020
  6. Pingback: Ad Last Login Date Powershell July 19, 2020
  7. Pingback: Ad Last Login Time July 19, 2020
  8. Pingback: Ad Show Last Login Time July 20, 2020
  9. Pingback: Ad User Last Login July 20, 2020
  10. Pingback: Ad User Last Login Date July 20, 2020
  11. Pingback: Ad User Last Login Time July 20, 2020

Leave a Comment


© 2000-2020 - - We're your center for technology focusing on InfoSec, Cybersecurity, Privacy, Security, Reviews and How-To's. Founded in 2000, TeckLyfe is based in Chicago, IL.

Reproduction without explicit permission is prohibited. All Rights Reserved.

This website uses cookies and third party services. Please view our Privacy Policy for more information.

About Us - Privacy Policy - Contact Us - Sitemap