Forum Discussion
Kali0
Jan 03, 2022Copper Contributor
Search emails last month with powershell
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).ToShortDateS...
- Jan 03, 2022
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
surajbudhani
Microsoft
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
Kali0
Jan 03, 2022Copper Contributor
Hi Surajbudhani
Thank you very for your help, it works !!
$FromDate = (Get-Date).AddMonths(-2).ToShortDateString()
$ToDate = (Get-Date).ToShortDateString()
$Query = '(From:"fca.org.uk") AND (Received:' + $FromDate + '..' + $ToDate + ")"
Search-Mailbox -Identity fcirulli -SearchQuery $Query -Targetmailbox "pgross" -Targetfolder "TEST" -Loglevel Full
Thank you very for your help, it works !!
$FromDate = (Get-Date).AddMonths(-2).ToShortDateString()
$ToDate = (Get-Date).ToShortDateString()
$Query = '(From:"fca.org.uk") AND (Received:' + $FromDate + '..' + $ToDate + ")"
Search-Mailbox -Identity fcirulli -SearchQuery $Query -Targetmailbox "pgross" -Targetfolder "TEST" -Loglevel Full