Hello all,
I am working on a script to find and delete emails in exchange online.
I’ve been browsing through the Powershell books wrote by Don and so far I have managed to come up with this.
[pre]
#Search-ABMEmails by MessageID
#Usage: Search.ps1 -MessageID [ID] | Delete-ABMEmails
function Search-ABMEmails {
[CmdletBinding()]
Param(
# MessageID
[Parameter(ValueFromPipeline=$true)]
[Parameter(ValueFromPipelineByPropertyName=$true)]
[Parameter(Mandatory=$true)]
[string[]]$MessageID
)#Param
Begin{}
Process{
$script:Trace=Get-MessageTrace-MessageID "$MessageID"|`
Select-Object-Propery @{name="Identity";expression={$_.RecipientAddress}}, SenderAddress,Subject |`
Format-Table-AutoSize
$script:RecipientAddress= [scriptblock]::Create($Trace.Identity)
$script:SenderAddress= [scriptblock]::Create($Trace.SenderAddress)
$script:Subject= [scriptblock]::Create($Trace.Subject)
Write-Output$Trace
}#Process
End{}
}#Search-ABMEmails
function Remove-ABMEmails {
foreach ($Identityin$Trace){
Search-Mailbox-Identity $RecipientAddress|`
Search-Query {Subject:"$Subject" AND From:$SenderAddress} -DeleteContent #Search-Mailbox -DeleteContent
}#foreach
}#Delete-ABMEmails
[/pre]
The command should work like this;
Search.ps1 -MessageID [ID] with the option to pipe it to the other function for deletion.
I have the impression that this will fail, still haven’t mastered enough Powershell knowledge.
I would be grateful if any of you PS experts could provide any advice on how to make this work.