What It Does
The script connects to Exchange Online as your app and reads the external sender identification setting and its allow list. When it is off, it turns it on. Outlook, Outlook for Mac, Outlook on the web and Outlook for iOS and Android then show an External label beside the subject of messages from outside the organization.
When you list AllowSenders, such as partner.com, *.partner.com or billing@partner.com, any that are not on the allow list yet are added, and every existing entry is kept. Entries already there are left alone and nothing is ever removed. The allow list holds at most 200 entries and 8 KB in all.
It changes only this one organization setting. It does not create a banner or a mail flow rule. If you already use a mail flow rule that adds text to the subject of external messages, disable it before you turn this on, so mail is not marked twice. The script cannot judge whether such a rule exists, so check your mail flow rules yourself.
Before it changes anything it saves the setting and the allow list to a before-state JSON file under the MSPOutpost data folder on this computer, and prints the path. Afterwards it reads the setting back, retrying for a short while, and ends with an error if it did not take. It checks the setting, not an Outlook client, which may take a while to show it. A second run after a real change ends OK. 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 change this setting, for example Exchange Administrator.
- Install the ExchangeOnlineManagement module (version 3.1 or later) on the computer.
- Check the mail flow rules for one that already marks external mail, and disable it first.
- Collect the partner domains for AllowSenders, then run with DryRun=true.
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: Sets external sender identification Enabled true and adds AllowSenders to its allow list; writes a before-state JSON file.
- Restart: It never restarts the machine.
- Typical run: Under a minute.
- Example answer: "External sender tag turned on; 2 allow-list entry(ies) added; before-state saved"
- 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.
- AllowSenders: Domains (partner.com), subdomain patterns (*.partner.com) or addresses (billing@partner.com) that should not get the External label, separated by comma, semicolon or new line. Default none. Entries are only added.
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.