Skip to content

Instantly share code, notes, and snippets.

@vexx32

vexx32/Alex.ps1 Secret

Created March 21, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/c162230e5352816fac90df23cc7b6bd6 to your computer and use it in GitHub Desktop.
Save vexx32/c162230e5352816fac90df23cc7b6bd6 to your computer and use it in GitHub Desktop.
function Search-ABMEmails {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]
$MessageId
)
begin{}
process{
foreach ($Id in $MessageId) {
Get-MessageTrace -MessageId $Id |
Select-Object -Property RecipientAddress, SenderAddress, Subject
}
}
end{}
}
function Remove-ABMEmails {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]
$MessageId
)
process {
foreach ($Id in $MessageId) {
$Trace = SearchABMEmails -MessageID $Id
foreach ($Identity in $Trace) {
Search-Mailbox -Identity $RecipientAddress -SearchQuery "Subject:$Subject AND From:$SenderAddress" -DeleteContent
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment