-
Notifications
You must be signed in to change notification settings - Fork 250
Extract Exchange Online information
exo-extract.ps1 extracts Exchange Online configuration, security, and compliance settings and writes them to JSON files for analysis or archiving. It produces a full configuration snapshot, plus AI-optimized summaries.
-
Parameter parsing and defaults
- Requires
-TenantDomain. - Optional parameters:
-OutputFolder,-Compact,-Credential,-SkipConnection,-ConnectionRetries,-MaxRetries,-JsonDepth. - Initializes global counters and tracking collections for errors, warnings, timings, and export metadata.
- Requires
-
Output directory setup
- If
-OutputFolderis provided, it is used directly. - Otherwise, the output directory defaults to the parent of the script folder.
- Creates the output directory if it does not exist.
- Builds a timestamp and a sanitized tenant identifier for filenames.
- If
-
Module validation
- Requires the ExchangeOnlineManagement module; if missing, the script stops.
-
Connection logic
- Tests for an active Exchange Online session using
Get-ConnectionInformationand a validation call toGet-OrganizationConfig. - If
-SkipConnectionis provided and there is no active session, the script exits. - Otherwise, attempts connection with retry logic:
- Interactive login if
-Credentialis not provided. - Uses retry delays and reports failures.
- Interactive login if
- Tests for an active Exchange Online session using
-
Pre-collection summary
- Prints a banner with tenant, user, PowerShell version, module version, output directory, and retry settings.
- Lists all categories that will be collected.
-
Category collection loop
- Iterates through a predefined list of categories.
- Each category has:
- Name
- Command (script block)
- Description
- Critical flag
- For each category:
- Displays progress
- Executes the command via retry logic
- Tracks count, duration, and success
- Records timings and per-category statistics
- Logs success or failure (critical vs non-critical)
-
Summary assembly and export
- Aggregates all raw results into a single full summary object.
- Writes JSON using
ConvertTo-Jsonwith configurable depth.
-
Compact summary export
- Builds a compact, AI-optimized summary with key fields and samples.
- Includes counts, samples, and selected properties to reduce size.
-
Ultra-compact summary (optional)
- If
-Compactis set, produces an ultra-compact summary for instant analysis. - Includes minimal metadata, quick stats, and critical indicators.
- If
-
Final report
- Displays generated file names.
- Summarizes total categories collected and total time.
- Prints actionable errors and warnings separately from generic retry failures.
-
TenantDomain(required): Tenant domain (e.g., contoso.onmicrosoft.com). -
OutputFolder(optional): Output directory for JSON files. -
Compact(optional switch): Generate ultra-compact summary in addition to full and compact summaries. -
MaxRetries(optional, default 3): Retry attempts for data collection commands. -
SkipConnection(optional switch): Skip connection attempt if already connected. -
Credential(optional): PSCredential object for non-interactive login. -
ConnectionRetries(optional, default 3): Retry attempts for connection. -
JsonDepth(optional, default 64): JSON serialization depth.
-
Invoke-WithRetry- Executes a script block with retry logic.
- Retries on transient errors (timeout, throttling, network issues).
- Logs critical vs non-critical failures.
-
Write-Warn/Write-Err/Write-Info/Write-Stat- Output helpers that also track global warning/error counts.
-
Format-TimeSpan- Formats durations into human-readable seconds, minutes, or hours.
-
Get-SafeCount- Counts items safely across nulls and enumerables.
-
Save-Json- Ensures
.jsonextension. - Skips empty data.
- Writes UTF-8 JSON and records file size metadata.
- Ensures
Each category is collected using the listed cmdlet(s), with retries and timing:
- Organization config (
Get-OrganizationConfig) — Critical - Mailboxes (
Get-Mailbox -ResultSize Unlimited | Select-Object *) — Critical - Mailbox permissions (
Get-MailboxPermissionper mailbox) — Critical - Transport rules (
Get-TransportRule) — Critical - Retention policies (
Get-RetentionPolicy) — Non-critical - Retention policy tags (
Get-RetentionPolicyTag) — Non-critical - Mobile device policies (
Get-MobileDeviceMailboxPolicy) — Non-critical - Inbound connectors (
Get-InboundConnector) — Non-critical - Outbound connectors (
Get-OutboundConnector) — Non-critical - Accepted domains (
Get-AcceptedDomain) — Critical - Remote domains (
Get-RemoteDomain) — Non-critical - Journaling rules (
Get-JournalRule) — Non-critical - Anti-spam policies (
Get-HostedContentFilterPolicy) — Critical - Anti-malware policies (
Get-MalwareFilterPolicy) — Critical - Safe Links policies (
Get-SafeLinksPolicy) — Non-critical - Safe Attachments policies (
Get-SafeAttachmentPolicy) — Non-critical - Sharing policies (
Get-SharingPolicy) — Non-critical - Email address policies (
Get-EmailAddressPolicy) — Non-critical - OWA policies (
Get-OwaMailboxPolicy) — Non-critical - Anti-phishing policies (
Get-AntiPhishPolicy) — Critical - ATP policies (
Get-AtpPolicyForO365) — Critical - Distribution groups + members (
Get-DistributionGroup+Get-DistributionGroupMember) — Non-critical - Unified groups + members (
Get-UnifiedGroup+Get-UnifiedGroupLinks) — Non-critical
The script creates files in the output directory. Filenames include a sanitized tenant domain and timestamp.
-
Full summary
- Filename pattern:
exo_summary_<tenant>_<timestamp>.json - Contains complete, unfiltered data for all categories, plus metadata:
- Error/warning counts
- Per-category timings
- Export metadata (file sizes)
- Collection date
- Filename pattern:
-
Compact summary
- Filename pattern:
exo_summary_<tenant>_<timestamp>_compact.json - AI-optimized selection of fields and samples:
- Mailboxes: first 200
- Mailbox permissions: first 400
- Transport rules: first 100
- Retention policy/tag samples: first 50
- Most other policies: first 25
- Distribution/Unified groups: first 75 groups with limited member samples
- Filename pattern:
-
Ultra-compact summary (only if
-Compactis specified)- Filename pattern:
exo_summary_<tenant>_<timestamp>_ultra-compact.json - Minimal snapshot with counts and health indicators:
- Total counts for mailboxes, rules, domains, groups
- Security policy counts
- Critical category presence
- Error and warning counts
- Filename pattern:
- Errors and warnings are tracked globally.
- At the end, the script separates:
- Actionable errors/warnings (specific failures)
- Generic retry failures (non-specific collection failures)
- Final output summarizes counts and actionable items.
- JSON depth defaults to 64 to avoid truncation of deeply nested objects.
- For empty collections, files are skipped rather than creating empty JSON.
- Transport rules are treated as informational when empty.
- The script reports timing per category and total execution time.
- Compliance review and archiving
- Configuration drift analysis
- Security posture and policy review
- AI-assisted analysis of EXO configuration