🎉 Our Microsoft 365 Reporting & Management Tool is now available in Azure Marketplace 🚀
This website uses cookies to improve your experience. We'll assume you're ok with this. Know more.
Exchange Online

How to Find Inactive Folders in Exchange Online Mailboxes

Over time, Exchange Online mailboxes can become cluttered with outdated or unused folders. Without clear insight into which folders are inactive, cleanup efforts become inefficient, increase storage usage, and may lead to compliance issues. This guide shows how to identify inactive mailbox folders in Exchange Online to optimize storage and streamline ongoing mailbox management.

Track All Inactive Folders in Exchange Online Mailboxes Using PowerShell

Microsoft 365 Permission Required
Report Reader Least Privilege
Global Administrator Most Privilege
  • Connect to the Exchange Online PowerShell using the cmdlet below.
  • Windows PowerShell Windows PowerShell
     Connect-ExchangeOnline
  • Execute the following command to get all inactive mailbox folders in Exchange Online that haven’t been accessed or modified in over 30 days.
  • Windows PowerShell Windows PowerShell
     Get-Mailbox -ResultSize Unlimited | ForEach-Object {
        $user = $_.UserPrincipalName
        Get-EXOMailboxFolderStatistics -Identity $user | Where-Object {
            $_.LastModifiedTime -lt (Get-Date).AddDays(-30) } |
            Select-Object Name, FolderType, FolderPath, LastModifiedTime, CreationTime, FolderSize, ItemsInFolder,
            @{Name = 'Mailbox'; Expression = { $user}},
            @{Name = 'InactiveDays'; Expression = { [int]((Get-Date) - $_.LastModifiedTime).TotalDays }}
    } | Export-Csv -Path "<FilePath>" -NoTypeInformation
  • Replace the <Filepath> with the desired file location to save the inactive email folders report.
Track All Inactive Folders in Exchange Online Mailboxes Using PowerShell
  • The exported report displays all mailbox folders that have been inactive for more than 30 days with details, such as the mailbox UPN, folder name, last modified time, folder size, items in the folder, inactive days, and more.

Find Inactive Folders in Exchange Online to Optimize Mailbox Storage and Performance

AdminDroid’s Exchange Online reporting tool provides deep insights into mailbox folders by various reports on created folders, recoverable items, permissions, and more. These reports assist admins in identifying inactive folders to maintain mailbox structure and ensure consistent email management.

Monitor Mailbox Folder Activity to Ensure Data Integrity in Exchange Online

Track all folder activities such as creation, deletion, and more to identify unauthorized changes and maintain a clear folder structure in Exchange Online.

Gain Insights into Public Folder Usage in Microsoft 365

Audit public folder changes in Exchange Online to prevent misuse and data leaks, as these folders provide shared access to organizational content.

Correlate Inactive Mailboxes with Inactive Folders for Smarter Cleanup

Track inactive mailboxes report along with inactive folders to get a complete view of unused user accounts for effective cleanup and storage optimization.

Easily Find Removed Folders Across User Mailboxes

Audit mailbox folder deletions in Exchange Online to confirm intentional cleanup of inactive folders, enhance data hygiene, and prevent accidental data loss.

Track Mailbox Folder Permissions to Protect Sensitive Data

Monitor folder permission changes to prevent unauthorised access, ensure ongoing protection, and achieve regulatory compliance.

Gain All Folder Stats to Manage Exchange Mailbox Storage

Check all mailbox folders in Exchange Online along with details like folder names, paths, sizes, and folder items to identify trends and optimize mailbox storage efficiently.

In summary, AdminDroid’s Exchange Online management tool provides comprehensive dashboards and actionable insights for admins into mailbox folder usage. Admins can also monitor folder activity, storage usage, and more reports..

Explore a full range of reporting options

Important Tips

Identify inbox rules that move emails to hidden folders or enable external forwarding to prevent data leaks and unauthorized access.

Apply retention rules for mailboxes and folders to preserve ex-employee data, protect critical information, and ensure compliance.

Use archive mailboxes in Exchange Online to reduce primary mailbox size and improve storage efficiency in your organization.

Common Errors and Resolution Steps

Below are common errors and troubleshooting fixes that may occur while finding inactive folders in Exchange Online mailboxes.

Error Connect-ExchangeOnline: The term 'Connect-ExchangeOnline' is not recognized as the name of a cmdlet, function, script, file, or operable program.

This error occurs when the required Exchange Online PowerShell module is not installed or cannot be found on your system.

Fix Verify that the Exchange Online Management module is properly installed and imported into your Windows PowerShell. If not, install the module using the cmdlet below.
Install-Module ExchangeOnlineManagement

Error User is not allowed to call Get-EXOMailboxFolderStatistics.

This error occurs when you execute the Get-EXOMailboxFolderStatistics cmdlet in Exchange Online PowerShell without sufficient permissions to access the mailbox data.

Fix Ensure you hold one of the following roles to access the mailbox: Global Admin, Exchange Admin, or Reports Reader.

Error Get-MailboxStatistics shows more items than the total count by Get-MailboxFolderStatistics for a mailbox.

This issue occurs because hidden system folders are internally used by Microsoft and do not appear in folder statistics but are included in the overall mailbox count.

Fix Rely on Get-MailboxFolderStatistics for user-visible folder counts and reporting, as Microsoft considers this discrepancy normal.

Error Get-MailboxFolderStatistics: Unable to retrieve mailbox folder statistics for the mailbox <UPN>. Couldn't find <UPN> as a recipient.

This error occurs when the specified mailbox address is incorrect or does not exist in Exchange Online.

Fix Verify that the mailbox UPN is correct and that the user exists in your Exchange Online using the cmdlet below.
Get-Mailbox

Error ./GetMailboxFolderStatisticsReport.ps1 cannot be loaded because running scripts is disabled on this system.

This error occurs when Windows PowerShell blocks the execution of the script due to security restrictions.
It usually happens when the file is downloaded from the internet and marked as unsafe, or when the execution policy is set to be restrictive.

Fix To resolve the error, run the cmdlet below.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser.

Error Get-EXOMailboxFolderStatistics: Identity is a mandatory value to provide for running.

This error appears when the Get-EXOMailboxFolderStatistics cmdlet is executed without specifying the required -Identity parameter.

Fix To resolve the error, specify a valid mailbox identifier and execute the cmdlet below.
Get-EXOMailboxFolderStatistics -Identity <UPN>
Frequently Asked Questions

Monitor and Control Mailbox Folder Activity for Organized Exchange Online

1. How to check mailbox folder sizes and the item count in Exchange Online?

When users exceed their mailbox storage quota, they lose the ability to send or receive mail. Instead of focusing solely on total mailbox size, admins should identify which folders consume the most storage. Since Exchange Online does not offer built-in folder insights, PowerShell helps to get the oversized folders and items count. With this data, admins can perform targeted cleanup to optimize performance and keep mailboxes active.

Find mail folder size and item count using PowerShell

  • Open the PowerShell and connect to the Exchange Online module using the cmdlet below.
    Connect-ExchangeOnline
  • Run the following cmdlet to get the mailbox folder size and item count of a specific Exchange Online mailbox.
    Get-MailboxFolderStatistics -Identity <UPN>| Select Name, FolderSize, ItemsInFolder
  • Replace the <UPN> with the specific UserPrincipalName to get detailed statistics of all folders for that user mailbox.
    get-folder-size-item-count-using-powershell
    The report shows the folder size and item count for a specific user mailbox, along with details of mailbox folders, such as archive, inbox, calendar, contacts, and more.

Identify mailbox folder size and item count using a PowerShell Script

  • The above cmdlet retrieves a list of folders with their size and item count for a specific user mailbox.
  • However, you must add filters and loops to access subfolder data and deleted item statistics, which makes the process more complicated and time consuming. So we have developed a PowerShell script to export a detailed mailbox folder statistics report.
  • Download and run the following script in the Administrator PowerShell.
get-folder-size-using-powershell-script

The above script connects to Exchange Online, goes through all mailboxes, and retrieves details, such as UPN, folder name, folder size, items in the folder, folder type, and more. You can also export the mailbox folder statistics report to a CSV file using the script.

Even with these native methods, admins still have to check manually through each mailbox and calculate total folder sizes to find the largest mailbox. AdminDroid simplifies this task with timely reports by finding the top mailbox with its total folder size.

Get insights into the mailboxes with the largest folder sizes in Exchange Online with AdminDroid!

  • Admindroid’s top mailboxes by total folder size report helps to find all the mailboxes with the largest total folder size to clean up the storage consuming mailbox folders.
  • Here, you can find top mailboxes with details, such as total folder sizes, UPN, sign-in status, license status, and more.
get-top-mailbox-by-foldersize-using-admindroid

Handy tip: Use the Schedule option available within the report to receive regular insights via email or Teams.

2. How to monitor recently created mailbox folders in Exchange Online?

Users may create unauthorized folders to bypass policies or retain confidential data without detection. Since the Exchange admin center doesn’t offer any way to track newly created mailbox folders, PowerShell is used to monitor folder creation. This proactive monitoring helps enforce folder policies, prevent misuse, and ensure organizational standards.

Monitor the newly created folders using Exchange Online PowerShell

  • Connect to the Exchange Online PowerShell module using the below cmdlet.
    Connect-ExchangeOnline
  • Run the cmdlet below to get folders recently created in the last 30 days in all mailboxes.
    $startDate = (Get-Date).AddDays(-30).ToUniversalTime() 
    Get-Mailbox | ForEach-Object { 
        $user = $_.UserPrincipalName 
        Get-MailboxFolderStatistics -Identity $user | Where-Object { 
             $_.CreationTime -gt $startDate -and 
             $_.FolderType -eq "User Created" 
        } | Select-Object @{
    	    Name = 'UserPrincipalName'; 
    	    Expression = { $user }
         },
         Name, 
         FolderPath, 
         FolderType, 
         CreationTime 
    } | Sort-Object CreationTime | Format-Table -AutoSize 
monitor-newly-created-mail-folders-using-powershell

The above report provides details such as UPN, folder name, folder type, creation time, and more for all recently created folders in Exchange Online.

Gain immediate access to pre-built reports on newly created folders, exportable in various formats with just a few clicks!

  • Admins can view the newly created folders in all mailboxes in the last 30, 60, 90 days, and so on by applying the Created Time filter.
  • Additionally, you can download the recently created folder report in multiple formats as CSV, PDF, HTML, and more for easy sharing and reporting.
recently-created-folders-using-admindroid

3. How to automate the creation of Outlook folders in all Exchange Online mailboxes?

When provisioning mailboxes for onboarding, admins should create a standardized Outlook folder structure like HR, Project, or Finance, etc, to maintain consistent and organized email management. Since Exchange Online doesn’t natively allow auto-creation of custom folders in user mailboxes, PowerShell becomes the essential approach for automating this process. While the New-MailboxFolder cmdlet exists, it's limited to the currently logged-in user. For organization-wide automation, Microsoft Graph API offers a more scalable and efficient solution.

Automate email folder creation with PowerShell

  • Firstly, register the app in Entra with permissions as MailRead.Write and MailboxFolder.ReadWrite.All using the script.
  • Then, connect to the Microsoft Graph PowerShell module by using the command below.
    $ClientId = "<ClientId>" 
    $TenantId = "<TenantId>" 
    $ClientSecret = "<ClientSecret>" 
    
    # Convert the client secret to a secure string 
    $ClientSecretPass = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force 
     
    # Create a credential object using the client ID and secure string 
    $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClientId, $ClientSecretPass 
     
    # Connect to Microsoft Graph with Client Secret 
    Connect-MgGraph -TenantId $tenantId -ClientSecretCredential $ClientSecretCredential 
    Replace <TenantId>, <ClientId>, and <ClientSecret> with the actual ClientID, TenantID, and ClientSecret.
  • Execute the below cmdlet to create a new mailbox folder across all Exchange Online mailboxes. Make sure to provide the folder name before execution of the below PowerShell snippet.
    param( 
          [Parameter(Mandatory = $true)] 
          [string]$FolderName 
      ) 
      $Users = Get-MgUser -All -Filter "assignedLicenses/`$count ne 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable Records |Select-Object Id, UserPrincipalName 
      foreach ($user in $Users) { 
          try { 
             $folder = Get-MgUserMailFolder -UserId $user.Id -Filter "DisplayName eq '$FolderName'" -ErrorAction Stop 
              if (-not $folder) { $null= New-MgUserMailFolder -UserId $user.Id -BodyParameter @{ DisplayName = $FolderName } 
                  Write-Host "Folder '$FolderName' created for $($user.UserPrincipalName)" -ForegroundColor Green} 
              else { Write-Host "Folder already exists for $($user.UserPrincipalName)" -ForegroundColor Yellow}} 
        catch { Write-Host "Inactive user or unable to access mailbox: $($user.UserPrincipalName)" -ForegroundColor Red }} 

For example, the above snippet creates a 'project management' folder by analyzing all mailboxes. It shows for whom the folder was created successfully and for whom it wasn’t, along with the respective error messages.

creation-of-identical-folders-in-all-mailboxes
created-folder-in-user-mailbox

The image shows a sample mailbox where the "project management" folder was successfully created.

4. How to manage permissions to mailbox folders in Exchange Online?

Some users only need to share specific folders like Inbox, Calendar, or custom folders, but not their entire mailbox. While users can manually delegate access, admins may need to set folder-level permissions centrally for troubleshooting or policy enforcement. PowerShell lets admins assign these permissions securely and enable controlled collaboration without exposing the full mailbox.

Manage mailbox folder permissions using PowerShell

  • Connect to Exchange Online PowerShell by using the command below.
    Connect-ExchangeOnline
  • To grant user specific permissions on a mailbox folder, run the cmdlet below.
    Add-MailboxFolderPermission -Identity "<UserUPN>:\<FolderName>" -User "<DelegateUPN>" -AccessRights <RolesOrPermissions>
  • Replace the following details in the cmdlet before execution.
    • <UserUPN>:\<FolderName> with a specific mailbox and folder name.
    • "<DelegateUPN>" with the delegate user to whom permissions will be granted.
    • <RolesOrPermissions> with the appropriate access rights in Exchange Online. (e.g., Editor, Reviewer, Owner, etc.)
    add-permission-to-folders
    Note: Ensure the folder path is accurate when adding permissions, as an incorrect path can expose information that is not meant to be shared. Also, make sure the required permissions are added to the parent folders before accessing or configuring subfolders.
  • To update permissions for an existing delegate, use the Set-MailboxFolderPermission cmdlet.
    Set-MailboxFolderPermission -Identity "<UserUPN>:\<FolderName>"-User "<delegateUPN>" -AccessRights <RolesOrPermissions> 
  • To remove permission from the specific user of that folder, use the Remove-MailboxFolderPermission cmdlet.
    Remove-MailboxFolderPermission -Identity "<UserUPN>:\<FolderName>" -User "<delegateUPN>" 
    Note: This action removes all permissions for the specified user on the given folder.
  • To list folder permissions, use the Get-MailboxFolderPermission cmdlet to audit and verify access rights.
    Get-MailboxFolderPermission -Identity "<UserUPN>:\<FolderName>" 
    get-specific-folder-permissions
    The above snippet lists all permissions assigned to a specific folder within a user's mailbox.

5. How to delete the mailbox folder in Exchange Online mailboxes?

Admins often create or observe Outlook folders like TestFolder, Important, etc, during onboarding, which later become no longer in use or non-compliant. Since the Exchange admin center doesn't support bulk folder deletion and manual cleanup is not scalable, admins need an automated solution. PowerShell with Graph API offers an automated way to remove such folders across multiple mailboxes efficiently. It helps to maintain hygiene mailboxes and improves folder consistency across users in Exchange Online.

Effortless mailbox folder deletion with PowerShell

  • Firstly, register the app in Entra with permissions as MailRead.Write and MailboxFolder.ReadWrite.All.
  • Then, connect to the Microsoft Graph PowerShell module by using the cmdlet below.
    $ClientId = "<ClientId>"  
    $TenantId = "<TenantId>" 
    $ClientSecret = "<ClientSecret>'" 
     
    # Convert the client secret to a secure string 
    $ClientSecretPass = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force 
     
    # Create a credential object using the client ID and secure string 
    $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClientId, $ClientSecretPass 
                                
    # Connect to Microsoft Graph with Client Secret 
    Connect-MgGraph -TenantId $tenantId -ClientSecretCredential $ClientSecretCredential 
    Replace <TenantId>, <ClientId>, and <ClientSecret> with the actual ClientID, TenantID, and ClientSecret.
  • Execute the below command to delete the Outlook folder, make sure you have included the correct mailbox folder name.
    param( 
        [Parameter(Mandatory = $true)] 
        [string]$FolderName) 
    $Users = Get-MgUser -All -Filter "assignedLicenses/`$count ne 0 and userType eq 'Member'" ` -ConsistencyLevel eventual -CountVariable Records | Select-Object Id, UserPrincipalName 
    foreach ($user in $Users) { 
       try { 
          $folder = Get-MgUserMailFolder -UserId $user.Id ` -Filter "DisplayName eq '$FolderName'" -ErrorAction Stop 
          if ($folder) { 
               Remove-MgUserMailFolder -UserId $user.Id -MailFolderId $folder.Id -Confirm:$false 
               Write-Host "Deleted folder '$FolderName' for $($user.UserPrincipalName)" -ForegroundColor Green 
           }else {Write-Host "Folder not found for $($user.UserPrincipalName)" -ForegroundColor Yellow}} 
       catch { 
           Write-Host "Inactive user or error accessing mailbox: $($user.UserPrincipalName)" -ForegroundColor Red} 
       }  
    Note: The folder structure is deleted after executing the above command and cannot be restored.
    delete-multiple-folders-using-mggraph
    The execution of snippet deletes the "Project" folder if present, else it displays "Folder not found" message. For restricted or inactive mailboxes, it triggers an "Inactive user" error.

6. How to get all deleted mailbox folders in the Exchange Online?

Mailbox folders can be deleted either accidentally or to hide suspicious content. When these deletions go unnoticed, it may result in the loss of sensitive data or missed security incidents. Admins can use PowerShell to track deleted folders across Exchange Online mailboxes for proactive security and recovery.

List all deleted mailbox folders in Exchange Online

  • Connect to the Exchange Online PowerShell module using the cmdlet below.
    Connect-ExchangeOnline
  • Run the below cmdlet to get folders that were deleted and can be restorable.
    Get-Mailbox -ResultSize Unlimited | ForEach-Object { 
        $mailbox = $_.UserPrincipalName 
        Get-MailboxFolderStatistics -Identity $mailbox | 
        Where-Object { $_.FolderPath -like "*/Deleted Items/*" } | 
        Select-Object @{Name="Mailbox"; Expression={$mailbox}}, Name, FolderPath, FolderType} 
    monitor-deleted-folders-using-powershell
    The above report gives visibility into folders under Deleted Items for the detection of recoverable folders and unusual deletion patterns. This strengthens mailbox oversight and supports compliance across the organization.

Kickstart Your Journey With
AdminDroid

Your Microsoft 365 Companion with Enormous Reporting Capabilities

Download Now
User Help Manuals Compliance Docs
x
Delivering Reports on Time
Want a desired Microsoft 365 reports every Monday morning? Ensure automated report distribution and timely delivery with AdminDroid's Scheduling to your email anytime you need.
Delivering Reports on Time
Schedule tailored reports to execute automatically at the time you set and deliver straight to the emails you choose. In addition, you can customize report columns and add inteligent filtering to the activities just from the previous day to suit your Microsoft 365 report requirements.
Set It, Schedule It, See Results- Your Reports, Your Way, On Your Time!
Time Saving
Automation
Customization
Intelligent Filtering
Give Just the Right Access to the Right People
Grant fine-tuned access to any Microsoft 365 user with AdminDroid’s Granular Delegation and meet your organization’s security and compliance requirements.
Give Just the Right Access to the Right People
Create custom roles loaded with just the right permissions and give access to admins or normal users within AdminDroid. The result? A streamlined Microsoft 365 management experience that aligns your organization's security protocols and saves your invaluable time and effort.
Align, Define, Simplify: AdminDroid's Granular Delegation
Smart Organizational Control
Effortless M365 Management
Simplified Access
Advanced Alerts at a Glance
Receive quick notifications for malicious Microsoft 365 activities. Engage with the AdminDroid’s real-time alert policies crafted to streamline your security investigations.
Advanced Alerts at a Glance
Stay informed of critical activities like suspicious emails and high-risk logins, bulk file sharing, etc. Through creating and validating ideal alert policies, AdminDroid provides a comprehensive approach to real-time monitoring and management of potential threats within your organization.
AdminDroid Keeps You Always Vigilant, Never Vulnerable!
Proactive Protection
Real-time Monitoring
Security Intelligence
Threat Detection
Merge the Required Data to One Place
Combine multiple required columns into one comprehensive report and prioritize the information that matters most to you with AdminDroid’s Advanced Column Customization.
Merge the Required Data to One Place
This column merging capability offers a flexible way to add different columns from various reports and collate all the essential data in one place. Want to revisit the customized report? Save it as a 'View’, and your unique report is ready whenever you need it.
Merge with Ease and Save as Views!
Custom Reporting
Unique View
Desired Columns
Easy Data Interpretation
Insightful Charts and Exclusive Dashboards
Get a quick and easy overview of your tenant's activity, identify potential problems, and take action to protect your data with AdminDroid’s Charts and Dashboards.
Insightful Charts and Exclusive Dashboards
With AdminDroid charts and dashboards, visualize your Microsoft 365 tenant in ways you've never thought possible. It's not just about viewing; it's about understanding, controlling, and transforming your Microsoft 365 environment.
Explore Your Microsoft 365 Tenant in a Whole New Way!
Executive overviews
Interactive insights
Decision-making
Data Visualization
Efficient Report Exporting for Microsoft 365
Downloading your reports in the right file format shouldn’t be a hassle with AdminDroid’s Report Export. Experience seamless report exporting in various formats that cater to your needs.
Efficient Report Exporting for Microsoft 365
Navigate through diverse options and export Microsoft 365 reports flawlessly in your desired file format. Tailor your reports precisely as you need them and save them directly to your computer.
Take Control, Customize and Deliver- Your Office 365 Data, Exported in Your Way!
Easy Export
Seamless Downloading
Data Control
Manage Microsoft 365

Get AdminDroid Office 365 Reporter Now!