Jan 03 2022 12:46 AM - edited Jan 03 2022 12:51 AM
Hi,
I try to search emails received from a specific sender during the last two months :
Here my request but It doesn't work on Exchange 2019 :
$fromDate = (Get-Date).AddMonths(-2).ToShortDateString()
$toDate = (Get-Date).ToShortDateString()
Search-Mailbox -identity blabla -SearchQuery {(From:"blabla.com") AND (Received:$fromDate..$toDate)' -Targetmailbox "blabla" -Targetfolder "TEST" -Loglevel Full
Could you please tell me how to put variables on the request ?
Thank you for your help
Jan 03 2022 03:33 AM
Solution
@Kali0
Try this and let me know if it works
$FromDate = (Get-Date).AddMonths(-2).ToShortDateString()
$ToDate = (Get-Date).ToShortDateString()
$Query = '{(From:"blabla.com") AND (Received:' + $FromDate + '..' + $ToDate + ")}"
Search-Mailbox -Identity blabla -SearchQuery $Query -Targetmailbox "blabla" -Targetfolder "TEST" -Loglevel Full
Jan 03 2022 04:31 AM
Jan 03 2022 03:33 AM
Solution
@Kali0
Try this and let me know if it works
$FromDate = (Get-Date).AddMonths(-2).ToShortDateString()
$ToDate = (Get-Date).ToShortDateString()
$Query = '{(From:"blabla.com") AND (Received:' + $FromDate + '..' + $ToDate + ")}"
Search-Mailbox -Identity blabla -SearchQuery $Query -Targetmailbox "blabla" -Targetfolder "TEST" -Loglevel Full