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.
- Connect to Office 365 via PowerShell. Use the guide below to connect
- http://itwalkthroughs.com/knowledge-base/connect-to-office-365-via-powershell-with-mfa-enabled-account/
- Once connected via PowerShell type the following command
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
