Newbie Question - Searching a variable with another variable

Hello all,

I use Office 365 and I have an issue where messages from out “allowed senders” list get stuck in Quarantine. I’ve created a rule that bypasses the SPAM filtering, but messages still get stuck. I wanted to run a script (timed via task manager) to scan every half hour to see if there are messages there. I can’t seem to get the results I want using a variable. Here is what I have:

Find the “Allowed Domains” from the rule: [pre] $Allowed = Get-TransportRule “Client Domain Whitelist” | select -ExpandProperty SenderDomainIs [/pre] This gives me a list of domains in the $Allowed variable. I then get the list of Quarantined messages: [pre] $QM = Get-QuarantineMessage [/pre] So now I want to search the $QM variable for the individual domains contained in $Allowed: [pre] foreach ($allow in $allowed) {select-string -inputObject $QM -pattern $allow -AllMatches}[/pre] I can’t get any output. Ideally, I’d like to expand the script, when it’s working, to send an email alerting us to the fact that there is a message from an “$allowed” domain in the quarantined messages. Thoughts?

[pre] Get-QuarantineMessage | ? {$_.Senderaddress -like “*”} | Out-File -Filepath “C:\Scripts\q.csv” [/pre] will work for an individual domain, but not if I use the $allow variable.

foreach ($Message in $QM) {
    foreach ($Allow in $Allowed) {
        if ($Message.senderaddress -like "*$Allow") {
            Write-Output $Message

Thank you!! That worked!