Skip to content

Instantly share code, notes, and snippets.

@mitchellurgero
Created June 26, 2018 21:39
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 mitchellurgero/45b52fd044a67d9a768b507a7fa78a6d to your computer and use it in GitHub Desktop.
Save mitchellurgero/45b52fd044a67d9a768b507a7fa78a6d to your computer and use it in GitHub Desktop.
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