I'm looking for a PS script that will delete an email sent by mistake to specific users. The goal here is NOT to query all mailboxes. I'm looking for a pre-canned script that I can edit the variables(subject, date sent), while pulling a list of users from a text file when needed "A text list would look something like (aliases or full display name); could do by DL using get-adgroupmember –recursive (an example would be appreciated!) to populate the text. We also would need to run this as an account that has full access to all mailboxes, so we need to put that right in script.
Would the following work:
Get-Content “C:\input.txt” | Get-Mailbox | Add-MailboxPermission –AccessRights FullAccess –User firstname.lastname@example.org –AutoMapping:$false
Get-Content “C:\input.txt” | Get-Mailbox | Search-Mailbox -SearchQuery “Subject: Executive Bonus From:email@example.com Sent:5/14/2015″ -DeleteContent -TargetMailbox “Restore-Mailbox” -TargetFolder “inbox” -loglevel full
Get-Content “C:\input.txt” | Get-Mailbox | Remove-MailboxPermission –AccessRights FullAccess –User firstname.lastname@example.org