12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with $subject value after 01st execution

vitusq opened this issue · comments

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?

What script is this problem in?

What script is this problem in?

PurgeMessagesWithContentSearch.PS1

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.
+ CategoryInfo : InvalidData: (:) [Remove-ComplianceSearchAction], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-ComplianceSearchAction
+ PSComputerName : che01b.ps.compliance.protection.outlook.com

All done!**

Try escaping the special character:

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

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

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.

  • CategoryInfo : InvalidData: (:) [Remove-ComplianceSearchAction], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-ComplianceSearchAction
  • PSComputerName : che01b.ps.compliance.protection.outlook.com

All done!**

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!

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)

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.

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