Search mailboxs and delete emails as per date subject and sender.


Search mailboxs and delete emails as per date subject and sender.


confirm the usual permissions needed for this operation,


Connect to the following as needed

$UserCredential = Get-Credential

#connect to exchange 0365
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
#connect to exchange onprem
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://YOUREXCHANGE/PowerShell/ -Authentication Kerberos -Credential $UserCredential
#sec and comp
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session


commands that I use and for memory...



just delete it no record?
get-mailbox -resultsize unlimited | Search-Mailbox -searchquery {Subject:'SUBJECT*' AND From:"USER@DODGYEMAIL.com" AND Sent:"6/17/2018"} -DeleteContent

delete it and give me a record.
get-mailbox -resultsize unlimited | Search-Mailbox -TargetMailbox "ADMIN" -TargetFolder "RANDOMFOLDER" -searchquery {Subject:'Planning sheet*' AND From:"USER@DODGYEMAIL.com" AND Sent:"6/17/2018"} -DeleteContent



Extras
Random mailbox commands

get mailbox commands that are not export mailboxes in o365


get-mailbox -resultsize unlimited | where {$_.Primarysmtpaddress -notlike "*_export_*" } |select Primarysmtpaddress |export-csv c:\temp\emailtemp5.csv -NoTypeInformation

Comments

Popular Posts