views:

971

answers:

1

How do you find out the last log-in time for a windows machine(any user) through powershell?

+1  A: 

It's apparently non-trivial when you involve domain controllers. Here's the code ripped from that blog entry (first one on google, by the way)

Without a Domain Controller:

(Get-QADUser username).lastLogon

With:

Get-QADComputer -ComputerRole
DomainController | foreach {
(Get-QADUser -Service $_.Name
-SamAccountName username).LastLogon.Value } |
Measure-Latest
Tom Ritter
Thanks Tom Ritter. I saw that one too before raising this question on SO. But my question is about last login time for any user on a machine (I'm not concerned about one particular user)
BlueGene