Last Logon Date Powershell Script for Office 365
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 reporting and and 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.
- Your Office 365 Administrator Username
- Your Office 365 Administrator Password
- 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
firstname.lastname@example.org,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?
These other blog posts may be of interest to you: