Date range -searchquery

by Feb 4, 2015

Hi All

I have been trying to get this to work in a script with no joy. The command works if i remove " SearchQuery {(Received -lt '$end') -and (Received -gt
'$start')}" What i am trying to do is to create a schedule task to do a search of a user mailbox dumpster every month

any help would be great

 

$start=(Get-Date).adddays(-30).addhours(-1)

$end=(Get-Date).adddays(-1).addhours(-1)

Search-Mailbox -Identity "user" -SearchDumpsteronly SearchQuery {(Received -lt '$end') -and (Received -gt '$start')}  -includeunsearchableitems -TargetMailbox searchresults -TargetFolder "searchresults" -Loglevel Full