Skip to content
Menu

Turn on the Archive and Auto-Expanding Archive

Enables missing online archives and, by default, enables auto-expansion wherever it is off. It skips mailboxes that already have the requested features and never deletes an archive.

Turn on the archive and auto-expanding archive is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Turn on the archive and auto-expanding archive. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: Organization.Read.All; ExchangeOnlineManagement 3.1+, Exchange.ManageAsApp, Exchange admin role
Changes thingsChanges what it runs on

What It Does

The script connects to Exchange Online as your app. For each user mailbox, or the one in TargetMailbox, that has no archive, it creates the online archive. Unless AutoExpanding is false, it then turns on auto-expanding archiving, which adds storage automatically as the archive nears its limit. The archive has to exist before auto-expanding can be turned on, and auto-expanding cannot be turned off again once it is on, so that part is permanent.

Mailboxes that already have an archive, and auto-expanding when you asked for it, are left alone. It does not touch shared mailboxes unless you name one in TargetMailbox, and it never deletes or disables an archive. Each change is recorded in the MSP Outpost change log.

It does not assign a retention policy. Mail moves into the archive through the mailbox's retention policy, and a mailbox with a blank policy is listed as a warning. Assigning one is left to a person, because a retention policy can also delete mail.

A mailbox whose license does not allow an archive fails with the message Exchange gives. The run goes on with the others and ends with an error that says how many failed. It reads back each setting it enables, including auto-expansion when requested, and fails that mailbox if the setting does not appear. Use DryRun=true first. If the ExchangeOnlineManagement module is not installed, the run is skipped.

Before You Run It

  • Register an app for this client with a certificate, and keep the certificate with its private key on the computer that runs the script.
  • Give the app the Microsoft Graph application permission Organization.Read.All and the Exchange.ManageAsApp permission.
  • Assign the app an Exchange role that can run Enable-Mailbox, for example Exchange Administrator. A read-only role is not enough.
  • Check that the licenses include archiving.
  • Run it once with DryRun=true and read the list.
  • Decide whether you want auto-expanding, because it cannot be turned off, and plan the retention policy separately.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Creates the online archive and turns on auto-expanding archiving (cannot be turned off again) for mailboxes that lack them.
  • Restart: It never restarts the machine.
  • Typical run: Under 10 minutes on a large tenant.
  • Example answer: "Enabled the archive on 3 mailbox(es) and auto-expanding archiving on 5"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The client's tenant ID (a GUID) or domain such as contoso.onmicrosoft.com. Required.
  • ClientId: The app registration's Application (client) ID, a GUID. Required.
  • CertificateThumbprint: Thumbprint of the app's certificate, with its private key in LocalMachine\My or CurrentUser\My on this computer. Preferred. Leave empty to use the ClientSecret environment variable.
  • TargetMailbox: One mailbox (its address or UPN). Default empty: every user mailbox.
  • AutoExpanding: true (default) to also turn on auto-expanding archiving (permanent); false to create the archive only.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

enable-mailbox-archive.ps1 · 1047 lines · 57.9 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.