How to export blocked address or domain by end user in Exchange Online

Introduction

This script will export blocked address or domain by end user in Exchange Online.

Scenarios

This script will export blocked address or domain by end user in Exchange Online.

Script

You can use this script in the following way.

1. Open Windows PowerShell.

2. Type the one command< Script Path> at the Windows PowerShell Console.
For example, type C:\Script\
EXOTopBlockedList.ps1

Here are some code snippets for your references.

PowerShell
Edit|Remove
Foreach($JunkAddress in $JunkList.BlockedSendersAndDomains)
        {
            if($BlockedList.Name -contains $JunkAddress)
            {
                $index = [array]::IndexOf($BlockedList.Name, $JunkAddress)
                $BlockedList[$index].Count += 1
            }
            else
            {
                $BlockedObj = New-Object PSObject
                $BlockedObj | Add-Member -membertype NoteProperty -Name Name -Value $JunkAddress
                $BlockedObj | Add-Member -membertype NoteProperty -Name Count -Value 1
                if($JunkAddress.contains("@"))
                {
                    $BlockedObj | Add-Member -membertype NoteProperty -Name Type -Value Email
                }
                else
                {
                    $BlockedObj | Add-Member -membertype NoteProperty -Name Type -Value Domain
                }
                $BlockedList += $BlockedObj
            }
        }

Examples

Example: Export the blocked list by end user to c:\report\blocked.csv

The sample is showed below
EXOTopBlockedList.ps1 -Credential $Credential  -ReportPath "C\Report" – FileName "blocked.csv"
Result Screenshot:

Prerequisites

Exchange Online
Windows PowerShell 2.0

 

 

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.