SOLVED

How to filter last 30 days on Get-MailboxSearch?

%3CLINGO-SUB%20id%3D%22lingo-sub-176374%22%20slang%3D%22en-US%22%3EHow%20to%20filter%20last%2030%20days%20on%20Get-MailboxSearch%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176374%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%0A%3CP%3EI%20have%20this%20script%20but%20I%20need%20to%20be%20able%20to%20report%20on%20the%20last%2030%20days%20only%3A%3C%2FP%3E%0A%3CPRE%3E%24When%20%3D%20(get-date).AddDays(-30).ToString(%22dd%2FMM%2Fyyyy%20HH%3Amm%3Ass%22)%0AGet-MailboxSearch%20%20%20%7C%20%20Select%20Name%2C%20InPlaceHoldEnabled%2C%40%7Bn%3D%22Export%20Date%22%3Be%3D%7B%5Bdatetime%5D(%24_.LastEndTime)%7D%7D%3C%2FPRE%3E%0A%3CP%3EI%20cannot%20find%20a%20way%20to%20be%20able%20to%20filter%20based%20on%20%24when.%3C%2FP%3E%0A%3CP%3EAny%20ideas%20please%3F%3C%2FP%3E%0A%3CP%3EM%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-176374%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EeDiscovery%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-176453%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20filter%20last%2030%20days%20on%20Get-MailboxSearch%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176453%22%20slang%3D%22en-US%22%3E%3CP%3EGot%20the%20solution%20-%20the%20date%20variable%20needs%20the%20same%20format%20as%20the%20property%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%24When%20%3D%20(get-date).AddDays(-30).ToString(%22MM%2Fdd%2Fyyyy%20HH%3Amm%3Ass%22)%0A%24holdsReport%20%3D%20Get-MailboxSearch%20%20%20%7C%20%20Select%20Name%2C%20InPlaceHoldEnabled%2C%40%7Bn%3D%22ExportDate%22%3Be%3D%7B%5Bdatetime%5D(%24_.LastEndTime)%7D%7D%7C%20Where-Object%20ExportDate%20-GT%20%24when%20%7C%20Sort-Object%20ExportDate%20-Descending%0A%3C%2FPRE%3E%0A%3CP%3EM%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-176418%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20filter%20last%2030%20days%20on%20Get-MailboxSearch%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176418%22%20slang%3D%22en-US%22%3EMight%20be%20easier%20to%20filter%20on%20the%20AD%20attrib%20msExchLitigatiomHoldDate%20then%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-176403%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20filter%20last%2030%20days%20on%20Get-MailboxSearch%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176403%22%20slang%3D%22en-US%22%3EHi%20%3CBR%20%2F%3EI%20am%20not%20searching%20for%20emails.%20all%20I%20want%20to%20to%20see%20is%20in-place%20hold%20accounts.%3CBR%20%2F%3EM%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-176383%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20filter%20last%2030%20days%20on%20Get-MailboxSearch%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-176383%22%20slang%3D%22en-US%22%3EIn%20your%20Get-MailboxSearch%2C%20you%20should%20be%20able%20to%20use%20-SearchQuery%20%22Sent%3A%20%24when%22%3C%2FLINGO-BODY%3E
Highlighted
Deleted
Not applicable

Hi

I have this script but I need to be able to report on the last 30 days only:

$When = (get-date).AddDays(-30).ToString("dd/MM/yyyy HH:mm:ss")
Get-MailboxSearch   |  Select Name, InPlaceHoldEnabled,@{n="Export Date";e={[datetime]($_.LastEndTime)}}

I cannot find a way to be able to filter based on $when.

Any ideas please?

M

4 Replies
Highlighted
In your Get-MailboxSearch, you should be able to use -SearchQuery "Sent: $when"
Highlighted
Hi
I am not searching for emails. all I want to to see is in-place hold accounts.
M
Highlighted
Might be easier to filter on the AD attrib msExchLitigatiomHoldDate then
Highlighted
Solution

Got the solution - the date variable needs the same format as the property:

 

$When = (get-date).AddDays(-30).ToString("MM/dd/yyyy HH:mm:ss")
$holdsReport = Get-MailboxSearch   |  Select Name, InPlaceHoldEnabled,@{n="ExportDate";e={[datetime]($_.LastEndTime)}}| Where-Object ExportDate -GT $when | Sort-Object ExportDate -Descending

M