Export Office 365 User Last Logon Date to CSV File

This script will connect to Office 365 and export a list of all your Office 365 Mailbox enabled users Last Logon Date/Time to a CSV file. It's useful for finding out if you're paying for any licences that aren't being used!

4.4 Star
55,367 times
Add to favorites
Office 365
E-mail Twitter del.icio.us Digg Facebook
  • The data returned by this script is invalid.
    4 Posts | Last post July 03, 2019
    • The LastLogonTime attribute does not reflect when the user logged in last only, but also when any process accessed the mailboxes.
      See this for more details: 
    • Wow, nice information!!
    • thanks!
    • Yes Jason, LastLogonTime reported by Get-MailboxStatistics gives inaccurate value because it also shows the last time when the background tasks like Mailbox Assistant accessed the mailbox. Most of the time, we use lastlogontime to identify users' last activity. You can get users' "Real last logon time"(I mean user's real last activity time) using Get-MailboxStatistics. 
      For more info, refer this blog. 
  • Is it possible to get a last login script for users that are not mail-enabled
    1 Posts | Last post May 02, 2019
    • Our users mailbox currently sits on an on premises Exchange server with a different domain than that of our Office 365
      I would like to check for user logins that aren't associated with a mailbox and have not found a way to do this. 
  • Hi,
    1 Posts | Last post March 21, 2019
    • Thanks for the useful script. When I go through a comment section, It inspired me to write a script to solve user requirement. I have added some additional attributes along with UserPrincipalName and Lastlogontime like DisplayName, Inactive Days, Assigned license, Admin roles, Mailbox type.
      You can check the script here: https://gallery.technet.microsoft.com/Export-Office-365-Users-ae3463f2
  • Not showing any results
    1 Posts | Last post January 29, 2018
    • I am getting this message when I run the script.
      WARNING: Your connection has been redirected to the following URI: "https://ps.outlook.com/PowerShell-LiveID?PSVersion=5.1.16299.98 "
      WARNING: The names of some imported commands from the module 'tmp_rkwu3oie.hkt' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of
      approved verbs, type Get-Verb.
      PS C:\WINDOWS\system32> .\Get-LastLogonStats.ps1 -Office365Username me@domain.org -Office365Password mypassword -UserIDFile c:\Files\InputFile.txt
      My InputFile.txt contains everyone's email addresses.
  • Input file problem
    1 Posts | Last post January 26, 2018
    • Is there a sample input file that you could add?  I get an error when I use an input file, not sure if it is the format of the file or something else.  If I run it without an input file it works fine.
  • date format problem
    1 Posts | Last post January 16, 2018
    • Hello
      Thx for greate script. I have small problem with output file.
      get-mailboxstatistics -Identity someone@contoso.com | Select LastLogonTime
      gives me output:
      15.01.2018 19:17:04
      but for the same person in output file I see:
      01/15/2018 19:17:04
      How to modify script to:
      - get date in dd/mm/yyyy format and without hour information
      - sort user descending by the date in output file
  • Large environment....
    1 Posts | Last post August 15, 2017
    • Hi
      I noticed that this isn't recommended for environments > 3000....
      Any suggestions for large environments (70,000)?!?
  • Another solution
    1 Posts | Last post January 30, 2017
    • https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx
      We will the command Get-MailboxStatistics so we can see the Value of the Last Login per mailbox user, below is the command
      Get-MailboxStatistics -identity "Alias" | select lastlogontime ("Alias" = Mailbox without quotes)
      And if you need a list users last login exported to a CSV file, please use the command below:
      (Get-Mailbox) | Foreach {Get-MailboxStatistics $_.Identity | Select DisplayName, LastLogonTime} | Export-CSV $Home\Desktop\LastLogonDate.csv
      Reference: https://technet.microsoft.com/library/mt771882(v=exchg.160).aspx
      And for the protocols used on your Organization to connect to the mailbox Get-ConnectionByClientTypeReport
      This command shows you an overview of all the connection types made into your organisation and is useful when you need to work out if ANYONE on your company is using a particular protocol
      Command is pretty straight forward to use, If you need to check the connection type within a certain period the command below is used:
      Get-ConnectionByClientTypeDetailReport -StartDate 06/01/2013 -EndDate 06/13/2013
      Please refer to the article https://technet.microsoft.com/en-us/library/jj873753(v=exchg.160).aspx
      Rafael Ruales
  • thanks for the script
    1 Posts | Last post September 22, 2016
    • its really helpful in the large organization
  • Add Alias or Display name?
    1 Posts | Last post September 21, 2016
    • Hi, Thanks for the script. Whats the best way to simply add the Display name, or the alias to the report?
1 - 10 of 44 Items