Direct Inward Dialing: +1 408 916 9393
Active Directory tracks a computer's last authentication in three attributes: lastLogon (accurate but stored per DC), lastLogonTimestamp (replicated domain-wide, updated every 9 to 14 days), and LastLogonDate (its readable DateTime form). For domain-wide queries, lastLogonTimestamp is the reliable choice.
This guide shows how to retrieve it using Get-ADComputer in PowerShell, Active Directory Users and Computers (ADUC), and ADManager Plus.
Import-Module ActiveDirectory
Import-Module ActiveDirectory
Get-ADComputer -Filter * -Properties LastLogonDate |
Select-Object Name, LastLogonDate
Use -SearchBase to scope the query to a single organizational unit instead of the entire domain:
Get-ADComputer -Filter * -SearchBase "OU=Workstations,DC=corp,DC=com" `
-Properties LastLogonDate | Select-Object Name, LastLogonDate
Assign a 90-day cutoff date to a variable, then pass it to -Filter to return only computer accounts that have not authenticated since that date:
$cutoff = (Get-Date).AddDays(-90)
Get-ADComputer -Filter {LastLogonDate -lt $cutoff} `
-Properties LastLogonDate, DistinguishedName | Select-Object Name, LastLogonDate, DistinguishedName
Pipe the results to Export-Csv to produce a flat file for auditing or compliance review:
Get-ADComputer -Filter * -Properties LastLogonDate, OperatingSystem | Select-Object Name, LastLogonDate, OperatingSystem | Export-Csv -Path "C:\Reports\ComputerLastLogon.csv" -NoTypeInformation
| Parameter | Description |
|---|---|
| -Filter | Filters which computers are returned. Use * for all computers, or a logical expression such as {LastLogonDate -lt $cutoff} for date-based filtering. |
| -Properties | Specifies additional attributes to retrieve alongside the default set. Use LastLogonDate for a readable DateTime value or lastLogonTimestamp for the raw 64-bit integer. |
| -Identity | Returns a single computer account by SAM account name, distinguished name, SID, or GUID. |
| -SearchBase | Restricts the search to a specific OU or container by distinguished name. |
| -SearchScope | Controls search depth relative to -SearchBase: Base, OneLevel, or Subtree (default). |
| -Server | Targets a specific domain controller instead of the one selected by default. |
ADUC does not convert lastLogonTimestamp to a readable date in the Attribute Editor. To interpret the raw value, run the following in PowerShell after substituting the integer:
[DateTime]::FromFileTime(<integer_value>)
The Active Directory module is not loaded or RSAT is not installed on the machine running the script. Install the RSAT Active Directory Domain Services and Lightweight Directory Services Tools component for your Windows version, then run Import-Module ActiveDirectory and retry the command.
A null LastLogonDate means lastLogonTimestamp has not been set for the account. This is expected for computer accounts that were added to the domain but have never completed a Kerberos authentication, or for accounts created before lastLogonTimestamp was introduced in Windows Server 2003 SP1. Confirm the account is enabled and has been used to sign in to a domain-joined device.
This is expected behavior. lastLogonTimestamp does not update at every logon; Active Directory updates it only when the elapsed time since the last stored value exceeds nine to 14 days. The value is accurate enough to identify accounts inactive over weeks or months, but not for day-level precision. If you need the most recent authentication time, query lastLogon on each domain controller individually.
Passing a calculated expression directly inside the filter braces can fail to evaluate correctly in some module versions. Assign the cutoff date to a variable first:
$cutoff = (Get-Date).AddDays(-90)
Get-ADComputer -Filter {LastLogonDate -lt $cutoff} -Properties LastLogonDate
Verify that the account has read rights for computer objects in the target OU, that the machine can reach a domain controller, and that the correct domain is being targeted. Use -Server to specify a domain controller explicitly if the default selection is resolving incorrectly.
lastLogon updates at every authentication but is stored only on the authenticating domain controller and is not replicated, so querying a single DC gives an incomplete view of the domain. lastLogonTimestamp replicates across all domain controllers but updates only every nine to 14 days, making it reliable for identifying inactive accounts over longer windows. LastLogonDate is the DateTime representation of lastLogonTimestamp that the Active Directory PowerShell module exposes; it holds the same value in a readable format. For domain-wide inactive computer queries, lastLogonTimestamp or LastLogonDate is the correct attribute to use.
Assign the cutoff date to a variable and pass it to -Filter:
$cutoff = (Get-Date).AddDays(-90)
Get-ADComputer -Filter {LastLogonDate -lt $cutoff} `
-Properties LastLogonDate, DistinguishedName | Select-Object Name, LastLogonDate, DistinguishedName
In ADManager Plus, the Inactive Computers report offers last 30-, 60-, and 90-day presets. With the Last Logon Time option selected, it queries lastLogon from all domain controllers, which is more precise than the replicated lastLogonTimestamp that PowerShell uses.
By design, lastLogonTimestamp does not update at every logon. Active Directory updates it only when the time elapsed since the last stored value exceeds a threshold of nine to 14 days, which limits replication traffic across domain controllers. The attribute is accurate enough to flag accounts inactive over weeks or months, but not for same-day precision.
Yes. Add -SearchBase with the OU's distinguished name to restrict the query:
Get-ADComputer -Filter * -SearchBase "OU=Workstations,DC=corp,DC=com" `
-Properties LastLogonDate | Select-Object Name, LastLogonDate
In ADManager Plus, the Computer Reports module supports OU-scoped filtering through the GUI without scripting.
Request lastLogonTimestamp in the -Properties list:
Get-ADComputer -Identity "PC01" -Properties lastLogonTimestamp | Select-Object Name, lastLogonTimestamp
To convert the raw 64-bit integer to a readable date:
[DateTime]::FromFileTime($computer.lastLogonTimestamp)
where $computer is the object returned by Get-ADComputer.