This toolkit provides PowerShell scripts to export all inbound security policies from Exchange Online into a consolidated CSV for review and management.
The toolkit includes four main components:
- Export-ExchangePolicies.ps1 - Exports all policies to CSV (requires Exchange Online connection)
- Analyze-ExchangePolicies.ps1 - Validates and analyzes the CSV (does NOT require Exchange Online)
- Apply-ExchangePolicies.ps1 - Applies decisions made in the CSV back to Exchange Online (requires Exchange Online connection)
- Analyze-TABL.ps1 - Optional TABL export and cross-reference report (requires Exchange Online connection)
- PowerShell 5.1 or later (PowerShell 7+ recommended)
- ExchangeOnlineManagement module installed:
Install-Module -Name ExchangeOnlineManagement -Repository PSGallery -Force
- Global Administrator or Security Administrator access in Microsoft 365
Collects all inbound security policy data from Exchange Online and exports to a CSV file.
The script retrieves all allowed/blocked/excluded entries from:
-
Anti-Spam Policies (HostedContentFilterPolicy)
- Allowed Senders & Domains
- Blocked Senders & Domains
- Excluded Senders & Domains
-
Anti-Phishing Policies (AntiPhishPolicy)
- Allowed Senders & Domains
- Blocked Senders & Domains
- Excluded Senders, Domains & Sub-Domains
-
Anti-Malware Policies (MalwareFilterPolicy)
- Allowed Senders & Domains
- Excluded Senders & Domains
-
Strict & Standard Preset Policies
- Same list types as above policies
-
Default Connection Filter Policy (HostedConnectionFilterPolicy)
- Allowed IPs (IP Allow List)
- Blocked IPs (IP Block List)
.\Export-ExchangePolicies.ps1This will create a CSV file in the current directory with a timestamp: Exchange_Policies_20260216_120000.csv
.\Export-ExchangePolicies.ps1 -OutputPath "C:\Exports\MyPolicies.csv"$cred = Get-Credential
.\Export-ExchangePolicies.ps1 -Credential $credThe exported CSV contains the following columns:
| Column | Description | Example |
|---|---|---|
| Object | The sender address, domain, or IP | user@example.com, example.com, 192.168.1.0/24 |
| PolicyType | Type of policy | Anti-Spam, Anti-Phishing, Anti-Malware, Connection Filter |
| PolicyName | Name of the specific policy | Default, Policy1 |
| ListType | Type of list entry | AllowedSenders, BlockedSenders, ExcludedSenders, AllowedDomains, BlockedDomains, ExcludedDomains, ExcludedSubDomains, AllowedIPs, BlockedIPs |
| TABL | Tenant Allow/Block List action (leave blank or enter: Allow / Block) |
|
| MailFlowRule | Mail flow rule action (leave blank or enter: Create) |
|
| DefaultConnFilter | Connection filter action (leave blank or enter: Add) |
|
| Remove | Remove from current policy (leave blank or enter: Yes) |
- Open the exported CSV in Excel or your preferred spreadsheet application
- Review each object and its source
- For each row, decide on ONE action:
- TABL: Add to Tenant Allow/Block List (enter
AlloworBlock) - MailFlowRule: Create Exchange mail flow rule (enter
Create) - DefaultConnFilter: Add to default connection filter (enter
Add) - Remove: Remove from current policy (enter
Yes)
- TABL: Add to Tenant Allow/Block List (enter
- Leave action columns blank if no action needed
- Save the CSV
Object,PolicyType,PolicyName,ListType,TABL,MailFlowRule,DefaultConnFilter,Remove
partner@trusted-partner.com,Anti-Spam,Default,AllowedSenders,Allow,,,
phishing.malicious.com,Anti-Spam,Default,BlockedDomains,Block,,,
trusted.partner.com,Anti-Spam,Default,AllowedDomains,Allow,,,
103.212.121.87/32,Connection Filter,Default,AllowedIPs,,, ,Block
malware.delivery.com,Anti-Malware,Default,BlockedDomains,Block,,,
trusted-sender@verified.com,Anti-Spam (Preset),Standard Preset Security Policy,AllowedSenders,Allow,,,
When you open the exported CSV in Excel, it will look like this:
| Object | PolicyType | PolicyName | ListType | TABL | MailFlowRule | DefaultConnFilter | Remove |
|---|---|---|---|---|---|---|---|
| admin@trusted.com | Anti-Spam | Default | AllowedSenders | Allow | |||
| phishing.com | Anti-Spam | Default | BlockedDomains | Block | |||
| trusted.com | Anti-Spam | Default | AllowedDomains | Allow | |||
| 192.168.1.0/24 | Connection Filter | Default | AllowedIPs | Add | |||
| virus.net | Anti-Malware | Default | BlockedDomains | Block | |||
| internal-test@corp.com | Anti-Spam | Default | ExcludedSenders | ||||
| staging.internal | Anti-Phishing | Default | ExcludedDomains | ||||
| partner@vendor.com | Anti-Phishing (Preset) | Standard Policy | AllowedSenders | Allow |
Color-coded for easy review:
- 🟢 Green "Allow" = Entries being allowed
- 🔴 Red "Block" = Entries being blocked
- 🔵 Blue "Add" = Entries to add to connection filter
- ⬜ Blank = No action planned
You can use Excel's built-in features to:
- Filter by PolicyType to see all Anti-Spam, Anti-Phishing, etc. entries separately
- Sort by ListType to group AllowedSenders, BlockedDomains, etc.
- Conditional Formatting to highlight rows with actions marked
- Add Comments for documentation of your decisions
Validates CSV integrity, provides analysis and statistics, and helps identify duplicates across policies. This script does not require an Exchange Online connection.
Run this script after exporting policies and before applying changes:
- Validate the exported CSV data
- Review summary statistics and policy breakdown
- Identify duplicate objects across policies
- Filter data by policy type, list type, or object pattern
- Export results by action type for focused review
Checks for invalid action values and highlights issues:
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action ValidateDisplays breakdown by policy type and list type:
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action SummaryIdentifies objects appearing in multiple policies:
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action FindDuplicatesShows entries from a specific policy type:
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action FilterByType -PolicyType "Anti-Spam"Shows entries from a specific list type:
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action FilterByListType -ListType "AllowedSenders"Creates separate CSV files grouped by action (TABL, Mail Flow Rule, etc.):
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action ExportByAction -OutputPath "C:\Exports"For detailed information about CSV columns, data types, and list types, see CSV_DATA_DICTIONARY.md.
Exports Tenant Allow/Block List entries (Sender, URL, FileHash, IP) and cross-references them against the consolidated policy CSV.
Run this script when you want a TABL-centric report that shows where those same values appear in policies.
.\Analyze-TABL.ps1 -InputCsvPath "C:\Exports\Exchange_Policies_20260216_120000.csv".\Analyze-TABL.ps1 -InputCsvPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -IncludeAdvancedDeliveryThe TABL analysis CSV includes:
- Primary
- TABLType (Sender, Url, FileHash, IP)
- ModifiedBy
- Action (Allow/Block)
- Notes
- Anti-Phishing (Preset) Policies
- Anti-Phishing Policies
- Anti-Spam Policies
- Connection Filter Policies
Reads the updated CSV and applies the marked actions to Exchange Online.
Displays what would be done without making changes:
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action PreviewGenerates a PowerShell script that can be reviewed before execution:
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action Export -OutputScript "C:\Exports\ApplyChanges.ps1"Then review the generated ApplyChanges.ps1 script and run it when ready.
Applies changes with a confirmation prompt:
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action Apply.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies_20260216_120000.csv" -Action Apply -SkipConfirmationAll generated scripts include built-in rollback capability! This allows you to safely test changes and undo them if needed.
The same generated script can be used to rollback all changes:
# Original apply command (first time)
.\ApplyChanges.ps1
# ... Test changes in your environment ...
# Rollback if needed
.\ApplyChanges.ps1 -Rollback- TABL Entries: Automatically removed using Get-TenantAllowBlockListItems and Remove-TenantAllowBlockListItems
- Connection Filter IPs: Automatically removed using Set-HostedConnectionFilterPolicy -IPAllowList/@{Remove='...'}
- Safe Operation: Handles edge cases like already-removed entries without failing
- No Manual Actions Required: Rollback for TODO items (Mail Flow Rules, policy removals) must still be done manually
========== ROLLBACK MODE ==========
Rolling back policy changes...
# ========== Action 1 ==========
Removing admin@trusted.com from TABL (Allow)...
✓ Removed successfully
# ========== Action 2 ==========
Removing 103.212.121.87 from Default Connection Filter (IPAllowList)...
✓ Removed successfully
========== ROLLBACK COMPLETED ==========
Total changes rolled back: 2
For a complete step-by-step guide to getting started, see QUICKSTART.md.
Step 1: Export Policies
# Run Export script (requires Exchange Online connection)
.\Export-ExchangePolicies.ps1 -OutputPath "C:\Exports\Exchange_Policies.csv"Step 2: Initial Analysis (no connection needed)
# Get summary statistics to understand current state
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action Summary
# Find duplicates across policies
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action FindDuplicatesStep 3: Review & Plan
- Open CSV in Excel or similar application
- Review each object and its source policy
- Use the Analyze script with filtering to focus on specific policy types or list types
- Decide on consolidation strategy (TABL, Mail Flow Rules, Connection Filter, or Remove)
- Mark your decisions in the appropriate action columns
Step 4: Validate CSV (no connection needed)
# Check for data entry errors
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action Validate
# Export by action type for focused review
.\Analyze-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action ExportByAction -OutputPath "C:\Exports"Step 5: Preview Changes (requires Exchange Online connection)
# See what will be applied without making changes
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action PreviewStep 6: Export Script (requires Exchange Online connection)
# Generate PowerShell script for review
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action Export -OutputScript "C:\Exports\ApplyChanges.ps1"Step 7: Review & Approve
- Review the generated
ApplyChanges.ps1script - Share with security team for approval
- Verify all changes match your plan
- Check for any manual actions needed (mail flow rules, policy removals)
Step 8: Apply Changes (requires Exchange Online connection)
# Option A: Run generated script directly
.\ApplyChanges.ps1
# Option B: Use Apply script with confirmation
.\Apply-ExchangePolicies.ps1 -CSVPath "C:\Exports\Exchange_Policies.csv" -Action ApplyStep 9: Verify
- Monitor the process output
- Check Exchange Online admin center for changes
- Verify TABL entries, mail flow rules, and connection filter updates
- Test with sample messages to ensure policies work as intended
Step 10: Rollback (Optional - If Issues Found) If you discover issues after applying changes:
# Use the same script to rollback all automated changes
.\ApplyChanges.ps1 -RollbackThis will automatically remove all TABL entries and revert Connection Filter IPs.
- Export & Apply require Exchange Online connection - Run from an admin machine with ExchangeOnlineManagement module
- Analyze can run anywhere - Useful for reviewing and planning without connection
- Always preview first - Use Preview mode before applying changes
- Generate script for approval - Use Export mode to create reviewable PowerShell script
- Test incrementally - Start with TABL entries, verify, then move to other actions
- Rollback available - Generated scripts include rollback capability for safe testing
- New in Microsoft 365
- Use for permanent allow/block decisions
- Entries can take up to 30 minutes to take effect
- Supports senders and IPs
- Better for long-term policy management
- More flexible for complex conditions
- Can include message properties, attachments, etc.
- Requires manual rule creation for now
- Better for conditional blocking
- Filters at SMTP receive connector level
- IP-based and domain-based filtering
- Legacy approach but still useful
- Takes immediate effect
- Be cautious when removing entries
- Verify impact before removing
- Consider moving to TABL instead of removing
Install-Module -Name ExchangeOnlineManagement -Repository PSGallery -Force
Import-Module ExchangeOnlineManagementClose existing PowerShell window with Exchange Online connection or use:
Disconnect-ExchangeOnline -Confirm:$falseEnsure account has Security Administrator or Global Administrator role:
- Go to https://admin.microsoft.com
- Navigate to Users > Active Users
- Select user and check Roles tab
- Verify internet connectivity
- Try closing and reopening PowerShell
- Run in PowerShell 7+ if possible
- Backup Original: Keep the original export before editing
- Use Filters: Use spreadsheet app filters to review by PolicyType or ListType
- Batch Actions: Group similar objects for bulk review
- Color Code: Use conditional formatting to highlight actions
- Comments: Add notes in a new column for context
- Limits: Consider TABL size limits (check Microsoft documentation)
- Sample Data: See SAMPLE_Exchange_Policies.csv for a realistic example
- Tenant Allow/Block List
- Mail Flow Rules in Exchange Online
- Connection Filter Policies
- Hosted Content Filter Policies
If you encounter issues:
- Check the logs in PowerShell output
- Verify your permissions and connectivity
- Ensure modules are up to date:
Update-Module ExchangeOnlineManagement - Try running in PowerShell 7+ (cross-platform)
-
v1.1 (2026-02-16): Rollback feature release
- Rollback capability for all generated scripts
- Fixed cmdlet syntax issues (TABL and Connection Filter)
- Added sample CSV file
- Enhanced documentation with visual examples
- Parser error fixes in Analyze script
-
v1.0 (2026-02-16): Initial release
- Export of anti-spam, anti-phish, anti-malware, and connection filter policies
- Preview, Export, and Apply modes for changes
- Comprehensive CSV output with action columns
These scripts are provided as-is for managing Exchange Online policies.
Always test in a non-production environment first. These scripts modify security policies and should be reviewed carefully before production use. Ensure proper backups and approvals are in place.