You are here

list users last login times in Powershell

$searcher = New-Object DirectoryServices.DirectorySearcher([adsi]"")
$searcher.filter = "(objectclass=user)"
$users = $searcher.findall()

Foreach($user in $users)
{
 if($user.properties.item("lastLogon") -ne 0)
  {
   $a = [datetime]::FromFileTime([int64]::Parse($user.properties.item("lastLogon")))
   "$($user.properties.item(`"name`")) $a"
  }
}