Finding inactive users in Office 365

When you log into your Office 365 admin portal, you’ll find a section called inactive email users under the service overview. This is all well and good, except that Microsoft doesn’t give you an option of finding out who these people are… so even though you have this awesome chart (below) you have no idea who the inactive users are – very frustrating!


Even clicking on View Table only gives you the same information, just in a different format:


Alan Byrne, from the Microsoft Script Center, has written an awesome script that you can use to figure out just who it is that hasn’t logged in for a month or two – it’s very handy for figuring out if you are paying for licenses that you aren’t using any more.

Download the script and execute it in PowerShell using the following command:

.Get-LastLogonStats.ps1 -Office365Username -Office365Password Password123 -InputFile c:FilesInputFile.txt

Of the three parameters, 2 are mandatory: -Office365Username and -Office365Password. The third parameter (-InputFile) allows you to specify the UserPrincipalNames of the people whom you would like to check – it will only return results for those users. A great thing about this script is that it will also show you users who have never logged on, not just the last logon date for users who have logged on.

Once you run the script, the csv file will be saved in the same folder you run the script from, and the results will look like this:


Once you have this list, you can decide if you want to delete any users – note that if you remove a license from a user, their data gets deleted immediately:

Caution:    When you remove the license from a user, any data associated with that user is deleted and cannot be recovered, except for documents saved on the Team Site. For example, that user’s mailbox and all messages contained in it are deleted.

Thankfully, you do get a warning first, but make sure you’re ready for the consequences before you remove anyone’s license!


Ah, PowerShell… how do I love thee? Let me count the ways! 😀

One thought on “Finding inactive users in Office 365

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.