Skip to content
Export guide · Email security

How to export your Microsoft Defender for Office 365 configuration, and what we check in it

Where you run it: Exchange Online PowerShell (Windows PowerShell 5.1, or PowerShell 7.6.0 or later on Windows, Linux or macOS).

In short

Microsoft Defender for Office 365 configuration export: the file Microsoft Defender for Office 365 writes of its own settings, which a configuration review reads setting by setting without connecting to Microsoft Defender for Office 365.

How to export the Microsoft Defender for Office 365 configuration, what the review checks in the file, and what it does not read.

The fileJSON, one o365.json holding four lists: AntiPhishPolicy, SafeLinksPolicy, SafeAttachmentPolicy and HostedContentFilterPolicy
Checks run on it52
Highest grade its findings reachOBSERVED
Feeds attack pathsYes
Not read from this export2 areas, listed below

Sources: Microsoft Defender for Office 365 documentation (1); Microsoft Defender for Office 365 documentation (2); Microsoft Defender for Office 365 documentation (3); the vendor table.

How to export it

Who can pull it
The Microsoft Entra role Security Reader
Time
About 10 minutes on a new computer (installing the module and signing in); about 3 minutes after that.
The file
JSON, one o365.json holding four lists: AntiPhishPolicy, SafeLinksPolicy, SafeAttachmentPolicy and HostedContentFilterPolicy

No console export: The Microsoft Defender portal (security.microsoft.com → Email & collaboration → Policies & rules → Threat policies) shows these policies. Microsoft describes its Export button on the Anti-phishing, Safe Links and Safe Attachments pages as exporting the list of policies to a comma-separated values (CSV) file, and our parser reads the settings inside each policy, so the export runs in Exchange Online PowerShell.

From the command line

  1. Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser(once per computer; installs Microsoft’s Exchange Online PowerShell module for your user, and an elevated PowerShell session is not required. Module versions 3.10.0 and later need PowerShell 7.6.0 or later; Windows PowerShell 5.1 runs every version of the module)

    The vendor's page, checked 2026-11-11
  2. Connect-ExchangeOnline -UserPrincipalName <your sign-in, for example you@contoso.com>(a Microsoft sign-in window opens; multi-factor sign-in works)

    The vendor's page, checked 2026-11-11
  3. $o365 = @{ AntiPhishPolicy = @(Get-AntiPhishPolicy) }

    The vendor's page, checked 2026-11-11
  4. $o365.SafeLinksPolicy = @(Get-SafeLinksPolicy)

    The vendor's page, checked 2026-11-11
  5. $o365.SafeAttachmentPolicy = @(Get-SafeAttachmentPolicy)

    The vendor's page, checked 2026-11-11
  6. $o365.HostedContentFilterPolicy = @(Get-HostedContentFilterPolicy)

    The vendor's page, checked 2026-11-11
  7. $o365 | ConvertTo-Json -Depth 10 | Out-File -Encoding utf8 o365.json

    The vendor's page, checked 2026-11-11
  8. Disconnect-ExchangeOnline -Confirm:$false(disconnects without a confirmation prompt. Microsoft: if you close the PowerShell window without disconnecting, you could use up the sessions available to you and need to wait for them to expire)

    The vendor's page, checked 2026-11-11

What the file looks like

JSON, one o365.json holding four lists: AntiPhishPolicy, SafeLinksPolicy, SafeAttachmentPolicy and HostedContentFilterPolicy. It varies with the number of policies in the tenant. The upload takes files up to 10 MB.

What it holds: Safe Links, Safe Attachments, anti-phish, and spam/content-filter policies.

o365.json is written in the current folder: the path PowerShell shows before the > of its prompt.

Afterwards

Run Disconnect-ExchangeOnline -Confirm:$false (the last step). Delete o365.json from your computer when the review is done. If you no longer need the module, run Uninstall-Module -Name ExchangeOnlineManagement . If you set the execution policy for this export, run Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser to remove it.

If the export goes wrong

What you seeThe fix
Connecting fails with "Files cannot be loaded because running scripts is disabled on this system."Run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser (the CurrentUser scope affects your user and no one else; Microsoft asks for Run as administrator for the LocalMachine scope), confirm if PowerShell asks, then run the Connect-ExchangeOnline line again. The setting is saved in the registry and stays until you change it back: see the clean-up line.
After you connect, PowerShell does not find Get-SafeLinksPolicy, Get-SafeAttachmentPolicy or another Get- command.After you connect, role-based access control (RBAC) decides which cmdlets your account has: check that the account holds one of the roles above, then run the Connect-ExchangeOnline line again. If a Get- command is still missing, leave its line out and run the rest: our parser reads the lists the file holds.
The upload says "Defender O365 input did not contain any expected policy collection".The file did not come from the ConvertTo-Json step (for example a single Get-AntiPhishPolicy | ConvertTo-Json). Run every $o365 line and then the ConvertTo-Json line in the same PowerShell window, and upload the o365.json it writes.

What we read from it

Checks run
52 + 4 guidance items, not counted
Formats read
PowerShell ConvertTo-Json export
Releases
2024.1 to current

Checks run is the number of checks that reached a result on this system's own export in our tests, as the vendor table shows it.

The areas checked

  • Anti-phishing policies: impersonation protection, spoof intelligence, thresholds
  • Safe Links and Safe Attachments policies
  • Anti-spam policies: bulk threshold, SPF handling, allow lists, zero-hour auto purge

The grade its findings reach

Observed Findings from this file are OBSERVED: read from the system's own export and cited to the setting.

Its findings feed attack paths: each one can be a step on a path an attacker could take to your crown jewels.

Attack paths, the one change and dollar figures are MODELED. How each grade is worked out is on the method page.

What we do not read from this export

  • Connection filter policy (IP allow and block lists): not in this export
  • DKIM signing and alert policies: not in this export
  • Preset security policies (Standard and Strict) and the users they cover: not in this export
  • Mail-flow (transport) rules: Get-TransportRule is a separate export
  • The Tenant Allow/Block List and safe-sender lists
  • Safe Attachments for SharePoint, OneDrive, and Microsoft Teams, Safe Documents, the common attachments filter and automatic external email forwarding: not in this export

Limits of the reader

  • If your export leaves a section out, the review does not flag it as partial.
  • The checks of this system are not counted: a check counts once a test shows it firing on a file in the layout the vendor documents.

A finding never comes from what the file does not hold: live traffic, running hosts and logs are not in a configuration export.

A Microsoft Defender for Office 365 finding from the sample company

Sample company: Acme Capital (fictional)

Outside auto-forwarding allowed

CriticalObservedDefender for O365 · outbound spam policy › forwarding

Run the sample to see this finding with its fix and the paths it sits on.

Questions

Who can export the Microsoft Defender for Office 365 configuration?

The Microsoft Entra role Security Reader is enough (Global Reader also works): Microsoft lists both as giving the permissions to view these policies, and after you connect, your roles decide which cmdlets you can run. In place of an Entra role, membership in the Exchange Online role group View-Only Organization Management also gives view access. A read permission in Microsoft Defender XDR Unified role based access control (RBAC) applies to the Defender portal, not to PowerShell.

Does the export change anything?

The Get- cmdlets view the policies and change none of them. On your computer the steps install the ExchangeOnlineManagement module for your user, keep a temporary copy of the module in the %TMP% folder, and write o365.json. An execution policy you set to fix an error stays until you change it back.

Does the file hold passwords or keys?

No password, secret or token setting is listed on Microsoft’s parameter pages for these four policy types, so none is expected in the file; read it before you send it. It holds the people you protect from impersonation (TargetedUsersToProtect, written "DisplayName;EmailAddress"), the senders and domains each policy allows or blocks, and redirect addresses. With redaction on (the default), the passwords, keys and tokens the review recognises are replaced with a placeholder before anything is stored; the check before upload shows how many it found.