Trouble filtering with where-object

Viewed 29

I can't seem to figure out why this where object filter is not working. here is the code:

Get-MailDetailTransportRuleReport -StartDate 08/25/2022 -EndDate 09/07/2022 
| Where-Object -Property SenderAddress -NotContains "@EMAIL-DOMAIN-HERE" 
| fl Date, Subject, Direction, SenderAddress, RecipientAddress, TransportRule

and I am of course, getting all of the results with the "@EMAIL-DOMAIN-HERE" still in it.

1 Answers

-notcontains is a collection containment operator, not a string comparison operator.

Use -notlike instead and make sure you include appropriate wildcards:

| Where-Object -Property SenderAddress -NotLike "*@EMAIL-DOMAIN-HERE" 
Related