Back to blog

Last Logon Date Powershell Script for Office 365

Aug 16, 2012 by Emma Robinson

A lot of people often ask us for tips on how to extract reporting information from Office 365. The easiest way is to use our Office 365 management tool. A much harder but equally effective way is to use the script below.

This script will connect to your Office 365 tenant and collect the last logon date of all the users in your company.

The script accepts three parameters.

  1. Your Office 365 Administrator Username
  2. Your Office 365 Administrator Password
  3. An input file path (optional)

When you run the script without an input file specified it will connect to Office 365 and collect the last logon time for all users in the tenant. It will output those to a file called LastLogonDate.csv with the following format

UserPrincipalName,LastLogonDate,08/16/2012 13:45:44,Never Logged In

If you provide an input file – a file with UserPrincipalNames in it, each one on a new line – it will only return the results for those users. This is useful for Office 365 tenants with lots and lots of users.

Feel free to ask any questions in the comments if you have problems.

You can download the script from the Microsoft Scripting Center.