Get Active Directory user account last logged on time (PowerShell)

This PowerShell Script shows how to use Windows PowerShell to determine the last time that a user logged on to the system.

22229.zip
 
 
 
 
 
4.3 Star
(40)
54,566 times
Add to favorites
Active Directory
9/1/2016
E-mail Twitter del.icio.us Digg Facebook
  • Not Working
    2 Posts | Last post March 12, 2019
    • I get the following error. Please help.
      
      ---------------------------
      Get-OSCLastLogonTime : The term 'Get-OSCLastLogonTime' is not recognized as the name of a cmdlet, function, script file, or operable program. 
      Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      At line:1 char:1
      + Get-OSCLastLogonTime -CsvFilePath C:\Script\SamAccountName.txt
      + ~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (Get-OSCLastLogonTime:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
      ---------------------------
    • First (after download) you should run Import-Module C:\Script\GetADUserLastLogonTime.psm1
      After this Get-OSCLastLogonTime is available
  • Change needed to read csv file
    1 Posts | Last post October 11, 2018
    • I had to edit the script to get it to successfully read the csv file.
      
      Change the line which imports the csv file to an object by removing ".SamAccountName" from the end of the line. After the change, it should be 
           $SamAccountName = (Import-Csv -Path $CsvFilePath)
         
      Change the line that queries AD by suffixing $UserName with ".SamAccountName" so that only the contents of that column are passed to the function. After the change, it should be
           QueryActiveDirectory -UserName $UserName.SamAccountName
      
      Once these changes are made and the modified script is imported with the -Force option, it should process your csv file successfully. No quotes or commas are required in the contents of your csv (unless your usernames contain embedded spaces).
  • Possibly misleading
    1 Posts | Last post September 18, 2018
    • Note that this script can be misleading, as it only queries the local AD DC. The script will only be accurate if you only have 1 DC in your domain, which makes the script kinda pointless for 99% of labs/organisations/domains!
  • Does not work with non english OS
    1 Posts | Last post June 08, 2018
    • For example on french Windows Server 2012 R2:
      AVERTISSEMENT : The SamAccountName 'DOE Oc?ane' cannot find. Please make sure that it exists.
  • Last Logon? Or Older Logon?
    1 Posts | Last post July 17, 2017
    • I did this for my username, and a few other usernames. I've obviously logged in today, but it says the last time I logged in was yesterday morning. I tried signing out and in, restarting my PC. Still says the same time. This script doesn't work perfectly. By far.
  • Poll Other DC's
    1 Posts | Last post June 01, 2017
    • Is it possible for this script to poll the other DC's on the network.
  • Doesn't work
    1 Posts | Last post November 05, 2016
    • Quite simply, does not work.  It says the user "Never Logon" when in fact the user logged in 2 days ago as shown in the security log.  I'm not sure what this is actually trying to do, but it does not list the user's last login to the machine you're running the script on.
  • Is it possible to see all users at once?
    2 Posts | Last post August 25, 2016
    • Is it possible to use the Get-OSCLastLogonTime -SamAccountName "username" command to see all the users at once? Rather than entering all of them manually. 
    • For the scripts of get all Active Directory users account last logged on time, see https://gallery.technet.microsoft.com/How-to-get-all-Active-832ca0c5 
  • weird results returned
    1 Posts | Last post July 26, 2016
    • i checked with my samAccountName and it says i haven't logged on for a week now! I login everyday so why does it say i haven't?
  • Issues using the CSV file
    2 Posts | Last post October 16, 2015
    • I'm also having an issue when using trying to run more than one username from the csv. I just get a blank output file if I redirect it. 
      
      any help would be great
    • Guys,
      
      
      You need to use the following format on .csv file
      
      "SamAccountName",
      "Mike.DUcilo",
      "Ary.Hai",
      "Marissa.Issa",
1 - 10 of 15 Items