What It Does
The script connects to Exchange Online as your app and lists the tenant's accepted domains. It keeps the authoritative ones, and drops the onmicrosoft.com domains, which Microsoft signs itself, and anything in SkipDomains.
For each remaining domain it reads the DKIM signing configuration, then looks up selector1._domainkey and selector2._domainkey on this computer. Each must be a CNAME pointing at the target the configuration names. Each domain gets a row showing the config, whether it is enabled, its status, how each selector looked up (resolves, missing or wrong target) and the problem in words.
It ends ALERT when any domain has no signing config, is not enabled, or has a selector that is missing or points to the wrong place. The alert uses Enabled and the DNS answers, not the status text. It never creates, changes or enables anything. Pair it with the enable script to fix what it finds.
If the ExchangeOnlineManagement module or the DNS lookup command is missing, it ends SKIPPED. Its DNS answers come from this computer's resolver, so a network with split DNS can differ from what the internet sees.
Before You Run It
- Install the ExchangeOnlineManagement module, version 3.1 or later, on the computer that holds the app's certificate.
- Give the app Organization.Read.All, Exchange.ManageAsApp and an Exchange role such as Exchange Administrator.
- List parked domains in SkipDomains so they do not alert.
- Run it from a computer whose DNS sees the public records, not only an internal view.
- Schedule it weekly and alert on exit 1.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 2 minutes.
- Example answer: "DKIM: 1 of 3 domain(s) not signing; contoso.com (not enabled; selector1 missing)"
- 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.
- SkipDomains: Accepted domains that never send mail (parked domains), separated by comma, semicolon or new line. Default none.
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.