How to find unused Exchange Online mailboxes

How to find unused Exchange Online mailboxes


What are unused Exchange Online mailboxes and how to identify them?


Unused Exchange Online mailboxes are user mailboxes which are currently not being used by their users. There are 3 ways in which we can identify if a mailbox is unused or not. They are:


1.The mailbox has been devoid of activity for a prolonged time. If there are no incoming or outgoing emails from the mailbox for an extended period, it can be classified as an unused account.


2. The mailbox has not been logged into for a long time. If there has been no login activity in the mailbox, it likely leads to the fact that no one is using that mailbox.


3. The owner of the mailbox is no longer with the organization. If the person who used to use that mailbox leaves and the administrator forgets to delete it, it becomes an unused mailbox.




With the per user cost of Exchange Online being $4, organizations have to pay $4 each for everyone of the unused Exchange Online user mailboxes present in their domain.

These unused mailboxes also result in wastage of licenses that can be assigned to other users. They also interrupt migration processes, wastage of storage space and can stand in the way of IT resource auditing.


Approaches to be taken by  an administrator

There are some approaches an administrator can take once they come across unused Exchange Online mailboxes:


  1. Contact its user to find out why the account is unused.
  2. Put a retention hold on the mailbox and delete the account to save licensing costs.
  3. Convert the unused account to a shared mailbox to save licensing costs while retaining mailbox data.


Whichever option they choose, unused Exchange Online mailboxes are best avoided as they pose both unnecessary financial costs and security concerns.


Finding unused Exchange Online mailboxes using PowerShell


You can run a script using the Exchange management shell to generate a list of users with required parameters like last log on time, etc.


The script below gives you a list of all mailboxes in your tenant arranged according to the last log-on date. You can discover when each user last logged on. The mailbox will be marked as inactive with the DisplayName, LastLoggedOnUserAccount, and LastLogonTime data if the last log on date was more than ninety days ago when this cmdlet was run.



Script 1:


  1. Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where{$_.Lastlogontime -lt (Get-Date).AddDays(-90)} | Select DisplayName, LastLoggedOnUserAccount, LastLogonTime




This above method is sometimes prone to errors as Exchange counts logins from Exchange Online service accounts. So, if a service account had accessed the unused mailbox to create a backup, Exchange Online counts it as a log on. Due to this, many of the unused mailboxes will be categorized as active. That is why we use other variables such as newest item receive date to get more accurate data. You can find the mailboxes classified according to the date it received the latest mail using the script below.


Script 2 : 


  1. $path = "c:\filename.csv"

  2. $mb = Get-EXOMailbox -RecipientTypeDetails Sharedmailbox -ResultSize unlimited

  3. Write-Host $mb.Count items.

  4. foreach ($m in $mb) 
  5. Write-Host Checking: $m.PrimarySmtpAddress - $counter
  6. $counter ++
  7. Get-EXOMailboxFolderStatistics -identity $m.PrimarySmtpAddress -IncludeOldestAndNewestItems | sort newestItemReceivedDate | where {$_.newestItemReceivedDate -ne $null} | select Identity,newestItemReceivedDate -last 1 | Export-Csv $path -Append -NoTypeInformation
  8. }


The export CSV command exports the data into a CSV file and saves it at the path specified. This file can be used for further scrutiny.

    • Related Articles

    • Generate an Activity Report for Microsoft 365 Groups and Teams

      Introduction The activity reports available for Microsoft 365 groups and Teams can be beneficial for administrators in an organization. Microsoft 365 teams group activity reports provide insight into group activities, group workloads, group counts, ...
    • Managing mailboxes and their quota limits in Exchange

      Management of the Microsoft Exchange environment in an organization is a comprehensive process. One of the various tasks is managing mailboxes, defining their quota limits, and identifying those that are over their given quota limit. This task can be ...
    • Powershell Script to Find and Replace Text in a File

      To find and replace a particular word throughout a file on multiple computers is as laborious as one can imagine. However, with the help of the following PowerShell script, one can easily find a particular word and replace it with a word of choice.   ...
    • Create a mailbox database in Exchange Server

      Manually provisioning mailbox databases to new users can be arduous. However, administrators can turn to PowerShell scripts to create mailbox database easily. The below script will create a mailbox database in an Exchange Server with the name 'D10'. ...
    • How to Find and Kill Running Processes with PowerShell

      Heavy hardware resource utilization on end-user machines will lead to reduced productivity by hindering users from getting their job done. In this article, we'll discuss how administrators can identify and kill memory-hogging processes. The following ...