18.5 C
Monday, February 6, 2023

Automate Enabling Archiving on Hybrid Office 365 Mailboxes

A Simple One Line script on a scheduled task will help you automate enabling archive mailboxes in Office 365. The below example checks for a custom attribute, archive status and enables a set of users in a specific OU. you can change as per your needs. In my case, this custom attribute is mapped to enable licenses dynamically.

# Include Exchange Powershell Module
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

#Lists All Remote Mailboxes
#Checks Archive Status
#Check License
#Enable Archive Mailboxes

Get-RemoteMailbox | Where-Object {($_.OnPremisesOrganizationalUnit -like "azure365pro.com/01 Users*") -and ($_.Ar
chiveStatus -like "None") -and ($_.CustomAttribute15 -like "O365*")} | Enable-RemoteMailbox -Archive

# Exit Exchange Powershell Module
Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

But for new users, every time administrators cannot keep checking to make sure Archive mailbox is enabled for my E3 and E5 users. it would be tiring to do it manually every time. So if require you can run it on a task scheduler so that it enables archive mailbox for all my E3 and E5 users.

Supported on Exchange 2013 or above | On-Premise Exchange Hybrid Server

NOTE: Before running the script run the below commands to check which are the mailboxes it will apply to

You can use Task Scheduler


Create Basic Task

Choose Daily


Set a time


Start a Program

  • Powershell
  • C:\Scripts\Enable_Archive_Mailbox.ps1

Made to stop the task if it exceeds 4 hours


Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles


Please enter your comment!
Please enter your name here

× How can I help you?