Chat with us, powered by LiveChat

Blog

Back

Last Logon Date Powershell Script for Office 365

16 Aug 2012 by Emma Robinson

Want to save this blog for later? Download it now.

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 reports.

A much harder but equally effective way is to use the script below.

Read more Optimizing PowerShell for large Office 365 tenants

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
user1@cogmotive.com,08/16/2012 13:45:44
user2@cogmotive.com,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.

If you found this blog post useful, and want to refer to it again, why not download it as a PDF?

Related Posts

These other blog posts may be of interest to you:

Grant Full Access to all mailboxes in Office 365