Asked by:
get Message Id using search-mailbox

Question
-
Is there a way to get messageId and other information when using search-mailbox command?
Get-Mailbox | Search-Mailbox -SearchQuery 'Subject:"Your bank statement"' -EstimateResultOnly
One thing I tried was copying the mail in to TargetMailbox and then run GetMessageTrackingReport cmdlet but its not working. Example
Get-Mailbox | Search-Mailbox -SearchQuery 'Subject:hello' -TargetMailbox 'kkk' -TargetFolder '123'
Search-MessageTrackingReport -Identity "kkk" -ByPassDelegatehecking | %{Get-MessageTrackingReport -Identity $_.MessageTrackingReportID -DetailLevel Verbose -ByPassDelegateChecking}
the above does not return anything event though 'kkk' has emails in it.
In the future is there a way to get email contents like body/to/from/subject?
- Edited by karanrshah Wednesday, January 3, 2018 6:39 PM
- Moved by Bill_Stewart Wednesday, February 14, 2018 7:23 PM This is not Exchange development forum
Wednesday, January 3, 2018 6:31 PM
All replies
-
Hi,
Please use the below format:
Use the Search-Mailbox cmdlet to search a mailbox and copy the results to a specified target mailbox, delete messages from the source mailbox, or both.
Search-Mailbox [-DeleteContent <SwitchParameter>] <COMMON PARAMETERS>
Search-Mailbox -TargetFolder <String> -TargetMailbox <MailboxIdParameter> [-DeleteContent <SwitchParameter>] [-LogLevel <Suppress | Basic | Full>] [-LogOnly <SwitchParameter>] <COMMON PARAMETERS>
Search-Mailbox -EstimateResultOnly <SwitchParameter> <COMMON PARAMETERS>
COMMON PARAMETERS: -Identity <MailboxOrMailUserIdParameter> [-Confirm [<SwitchParameter>]] [-DomainController <Fqdn>] [-DoNotIncludeArchive <SwitchParameter>] [-Force <SwitchParameter>] [-IncludeUnsearchableItems <SwitchParameter>] [-SearchDumpster <SwitchParameter>] [-SearchDumpsterOnly <SwitchParameter>] [-SearchQuery <String>] [-WhatIf [<SwitchParameter>]]
For Example:
This example searches the mailbox of Joe Healy and copies the search results to the DiscoveryMailbox in the folder JoeHealy-ProjectHamilton.
Search-Mailbox -Identity "Joe Healy" -SearchQuery "Subject:Project Hamilton" -TargetMailbox "DiscoveryMailbox" -TargetFolder "JoeHealy-ProjectHamilton" -LogLevel Full
This example searches April Stewart's mailbox for messages that contain the phrase "Your bank statement" in the subject and logs the result in the SearchAndDeleteLog folder in the administrator's mailbox. Messages aren't copied to the target mailbox.
Search-Mailbox -Identity "April Stewart" -SearchQuery 'Subject:"Your bank statement"' -TargetMailbox "administrator" -TargetFolder "SearchAndDeleteLog" -LogOnly -LogLevel Full
This example searches April Stewart's mailbox for messages that contain the phrase "Your bank statement" in the subject and deletes the messages from the source mailbox. You have to be assigned the Mailbox Import Export management role to use the DeleteContent switch.
Search-Mailbox -Identity "April Stewart" -SearchQuery 'Subject:"Your bank statement"' -DeleteContent
This example searches all mailboxes in your organization for messages that contain the words "election", "candidate", or "vote". The search results are copied to the Discovery Search Mailbox in the folder AllMailboxes-Election.
Get-Mailbox | Search-Mailbox -SearchQuery 'election OR candidate OR vote' -TargetMailbox "Discovery Search Mailbox" -TargetFolder "AllMailboxes-Election" -LogLevel Full
Thanks
Saurabh
Wednesday, January 3, 2018 8:15 PM -
This is absolutely not relevant to the questionWednesday, January 3, 2018 10:24 PM
-
This is absolutely not relevant to the question
The answer is still that Search cannot get what you want. You must get the messages returned by a search to get the message contents.
You can use the EWS API to search for messages and return that information.
\_(ツ)_/
Wednesday, January 3, 2018 10:27 PM -
Hi,
you also try to get tracking logs for particular identity "kkk" and it was not showing the output for the command that you have used above. Please go through the below link, i hope you will able to get help
https://technet.microsoft.com/en-us/library/aa997573(v=exchg.160).aspx
Thanks
Thursday, January 4, 2018 7:12 AM