Instantly share code, notes, and snippets.

Embed
What would you like to do?
Search mailbox in Exchange 2013/2016 for keywords, save to a targetMailbox then export PST.
# Search Mailbox's for given keywords
#
# Make sure the targetMailbox exists, if the folderName folder does not that will be created automatically.
#
#
# Made by Mitchell Urgero
#
#
# For Exchange 2013/2016
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
$idents = "" # username's of mailboxes you want to search EX: $idents = "user1","user2","user3"
$targetMailbox = "" # Mailbox where to save results (before export to PST)
$folderName = "" # Folder in TargetMailbox to put the results (before export to PST)
$searchTerm = "" # search term to use in idents mailbox(s) (same as what you would use in outlook)
$resultPath = "" # UNC path to export the PST to
foreach($i in $idents){
Write-Host "Searching $i"
search-mailbox -Identity "$i" -searchquery "$searchTerm" -targetmailbox "$targetMailbox" -TargetFolder "$folderName" -loglevel full
}
New-MailboxExportRequest -Mailbox "$targetMailbox" -IncludeFolders "$folderName" -FilePath "$resultPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment