title: Active Directory Users login and logoff sessions history
body: <p>I am looking for a script to generate the active directory domain users login and logoff session history using PowerShell. Below are the scripts which I tried. These show only last logged in session.</p>
  
  <p><strong>Script:</strong></p>
  
  <pre class="lang-csh prettyprint-override"><code>$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"
    }
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <blockquote>
    <p>PS C:\Windows\system32> C:\Users\Administrator\Desktop\working\lastlogonworked.ps1<br>
    Administrator 10/17/2013 13:11:31<br>
    DEMO 10/17/2013 13:10:54<br>
    User0 10/17/2013 07:07:07<br>
    User1 10/17/2013 06:29:27<br>
    User2 10/17/2013 08:39:05<br>
    User4 10/17/2013 08:41:36<br>
    User5 10/17/2013 09:38:07<br>
    CPU054 10/17/2013 13:11:53  </p>
  </blockquote>
  
  <p>Please someone help me to get the all users login and logout history.</p>