12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples
MIT License
1.28k stars 567 forks source link

CleanUpMailbox-Graph.PS1 issue #64

Closed oXydus closed 1 year ago

oXydus commented 1 year ago

Hi. In the row 200 instead of $SearchFilter = $SearchFilter + " AND '" + $SearchQuery + "'" } is better to write $SearchFilter = $SearchFilter + " AND " + $SearchQuery + "" }

I have no results with original row.

12Knocksinna commented 1 year ago

The single quotation mark is needed to generate a search filter and URI that looks like:

https://graph.microsoft.com/v1.0/users/eff4cd58-1bb8-4899-94de-795f656b4a18/mailfolders/AAMkADAzNzBmMzU0LTI3NTItNDQzNy04NzhkLWNmMGU1MzEwYThkNAAuAAAAAAB_7ILpFNx8TrktaK8VYWerAQBe9CuwLc2fTK7W46L1SAp9AAAA2lHHAAA=/messages?$search="subject:365 Service Alert AND from:o365mc@microsoft.com AND received>=2022-01-01 AND received<=2022-10-10 AND 'Microsoft'"&$select=id,parentfolderid,receivedDateTime,subject,from

I'm having some issues with search at the moment. I wonder if it's a glitch.

oXydus commented 1 year ago

Forgot to mention that with original script, if I use -SearchQuery "hasattachment:true", there are no results returned. And only cutting single quotation marks helped. Thank you very much for your script! Saved me a lot of time (before I used New-ComplianceSearch and it was a real pain. Yes, I know MS does not recommend ComplianceSearch for cleaning up the mailbox)

12Knocksinna commented 1 year ago

The quotation marks are needed when one or more keywords are in the $SearchQuery variable. When I get some more time, I will have a look at this again and see if I can improve the logic a tad.