12Knocksinna / Office365itpros

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

Issue with $subject value after 01st execution #55

Closed vitusq closed 2 years ago

vitusq commented 2 years ago

Hi I notice an "issue" here. if the subject being searched for contains a $xx in it, the content search leaves it out and only takes all the other text around it.

This is the subject of an email I was using: [External Email] Free and $10 Udemy coupons by Learn Viral

when the contentsearch is view, it can be seen that the subject being searched for is: [External Email] Free and Udemy coupons by Learn Viral

This causes in accurate or new result at the end. what could be the issue here?

12Knocksinna commented 2 years ago

What script is this problem in?

vitusq commented 2 years ago

What script is this problem in?

PurgeMessagesWithContentSearch.PS1

vitusq commented 2 years ago

I also ran into another issue. When there's no special character similar to the earlier one i mentioned, and when every value entered is accepted fine by the script, it executes and does it thing, but at the very end, it throws the following error:

Deleting items... ( 1 ) _Cannot bind argument to parameter 'Identity' because it is null.

All done!**

12Knocksinna commented 2 years ago

Try escaping the special character:

$Subject = "Special `$10 offer" - This needs to be done for PowerShell otherwise the special character is omitted.

12Knocksinna commented 2 years ago

Does the search action exist? If it didn't (because it wasn't created beforehand), you'd get that error.

vitusq commented 2 years ago

I made a small addition to your script. I've just added in $ContentSearchName to avoid having to modify the search name in all the places of the script every time this needs to be executed. I've attached the script here for your reference.

DeleteEmailfromALLmailboxes.txt

Irrespective of the modification or not, it still throws the error:

**Deleting items... ( 1 ) Cannot bind argument to parameter 'Identity' because it is null.

All done!**

vitusq commented 2 years ago

Try escaping the special character:

$Subject = "Special `$10 offer" - This needs to be done for PowerShell otherwise the special character is omitted.

This made it work right :D

Thank you!

vitusq commented 2 years ago

Does the search action exist? If it didn't (because it wasn't created beforehand), you'd get that error.

As i see in the script, there is a creation for the ComplianceSearch (line 28) and later for the ComplianceSearchAction (line 53)

12Knocksinna commented 2 years ago

OK. I have made some updates to the script, including your suggestion of using a variable for the search name (and one for the purge action name). Also added ErrorAction to make sure that errors aren't reported when unnecessary. I'm closing this now.

vitusq commented 2 years ago

I'll give the updated script a try and will get back to you