Skip to content

Instantly share code, notes, and snippets.

@s4parke
Created January 26, 2022 16:22
Show Gist options
  • Save s4parke/7128d755db0ad89f01f7ad7f8550dd57 to your computer and use it in GitHub Desktop.
Save s4parke/7128d755db0ad89f01f7ad7f8550dd57 to your computer and use it in GitHub Desktop.
Search for Blocked or Trusted Senders and Domains in Exchange Online
function Search-BlockedSendersAndDomains {
<#
.DESCRIPTION
Search by keyword in a user's blocked senders and domains.
Wildcards are automatically added before and after the search string.
.PARAMETER Identity
Email address of the user. "[email protected]".
.PARAMETER Term
Keyword search string. "example.com"
.INPUTS
A pipeline of user identities might work.
.OUTPUTS
System.String.
.EXAMPLE
PS> Search-BlockedSendersAndDomains -Identity "[email protected]" -Term "baz"
[email protected]
.EXAMPLE
PS> Search-BlockedSendersAndDomains "[email protected]" "noreply"
[email protected]
.EXAMPLE
PS> $users = @("[email protected]", "[email protected]")
PS> $users | Search-BlockedSendersAndDomains -Term "bubliz"
[email protected]
[email protected]
#>
param(
[Parameter(Mandatory, ValueFromPipeline, Position=0)]
[string]$Identity,
[Parameter(Mandatory, Position=1)]
[string]$Term
)
Process {
Get-MailboxJunkEmailConfiguration -Identity "$Identity" |
Select -ExpandProperty BlockedSendersAndDomains |
Where-Object {$_ -like "*$Term*"} |
Sort-Object
}
}
function Search-TrustedSendersAndDomains {
<#
.DESCRIPTION
Search by keyword in a user's Trusted senders and domains.
Wildcards are automatically added before and after the search string.
.PARAMETER Identity
Email address of the user. "[email protected]".
.PARAMETER Term
Keyword search string. "example.com"
.INPUTS
A pipeline of user identities might work.
Use the -Term parameter
.OUTPUTS
System.String.
.EXAMPLE
PS> Search-TrustedSendersAndDomains -Identity "[email protected]" -Term "baz"
[email protected]
.EXAMPLE
PS> Search-TrustedSendersAndDomains "[email protected]" "noreply"
[email protected]
.EXAMPLE
PS> $users = @("[email protected], "[email protected]")
PS> $users | Search-TrustedSendersAndDomains -Term "bubliz"
[email protected]
[email protected]
#>
param(
[Parameter(Mandatory, ValueFromPipeline, Position=0)]
[string]$Identity,
[Parameter(Mandatory, Position=1)]
[string]$Term
)
Process {
Get-MailboxJunkEmailConfiguration -Identity "$Identity" |
Select -ExpandProperty TrustedSendersAndDomains |
Where-Object {$_ -like "*$Term*"} |
Sort-Object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment