1. Home
  2. Office 365
  3. Export Last Logon Time for Office 365 Users to CSV via PowerShell
  1. Home
  2. PowerShell
  3. Export Last Logon Time for Office 365 Users to CSV via PowerShell

Export Last Logon Time for Office 365 Users to CSV via PowerShell

When maintaining Office 365 tenants in can be helpful to know the last logon time for users. It can be used to check for account inactivity to help free up Office 365 licenses etc.

Invoke-Command -Session (Get-PSSession) -ScriptBlock {Get-Mailbox -RecipientTypeDetails UserMailbox -Resultsize Unlimited | Get-MailboxStatistics | Select-Object DisplayName,LastLogonTime} | Export-CSV "filename.csv" -NoTypeInformation
  • Press Enter
  • PowerShell will now export a list of all Office 365 users with their last login information
  • “filename.csv” is a variable for where you want to save the file. In the example below I am saving the file to the C:\Temp folder
  • Once the export is complete you will find the CSV file in your chosen location
  • Open the .CSV file and you will see the list of Office 365 users and their last login time
  • The following is an example of the Outputted .CSV file
Updated on November 19, 2022

Was this article helpful?

Related Articles

Leave a Comment