What It Does
The script connects to Exchange Online as your app and works on the domains you name in Domains, or on every authoritative custom domain if you leave it empty. The onmicrosoft.com domains are skipped because Microsoft signs them itself. A name that is not an accepted domain stops the run.
For a domain with no signing config it creates one switched off, with the key size you chose. It then prints the two CNAME records, selector1._domainkey and selector2._domainkey and their targets, for you to publish at the domain's DNS host. A new config that is switched off changes no mail.
When both records resolve on this computer to those targets, it enables signing and re-reads the config, and fails if signing is not on. Until then it enables nothing for that domain, so run it again after the DNS change has spread, which can take a few hours. A domain already enabled is left alone, and a second run after everything is on changes nothing.
It never changes DNS and never disables signing. Enabling only adds a signature to outgoing mail, so note it in the client's change log. A dry run lists the configs it would create and the domains it would enable, and changes nothing.
Before You Run It
- Run it with DryRun=true first to see which domains it would touch.
- Know who hosts the client's DNS. You or the client must publish the two CNAMEs the script prints.
- Install ExchangeOnlineManagement 3.1 or later; give the app Exchange.ManageAsApp and an Exchange role such as Exchange Administrator.
- Run it again after the records have spread. The first run usually ends waiting for DNS.
- Use KeySize 1024 only if the client's DNS host cannot hold a 2048-bit key.
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 DKIM signing configs in Exchange Online; enables DKIM signing for a domain once both selector CNAME records resolve.
- Restart: It never restarts the machine.
- Typical run: Under 2 minutes.
- Example answer: "DKIM: created 1 config(s), enabled 1 domain(s); 1 waiting for DNS (CNAMEs printed above)"
- 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.
- Domains: Domains to work on, separated by comma, semicolon or new line. Default empty: every authoritative accepted domain except the *.onmicrosoft.com ones. A name that is not an accepted domain is an error.
- KeySize: Key size for a new signing config: 2048 (default) or 1024. Ignored for a domain that already has a config.
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.