These filters are black boxes that no one understands how they really work. It’s trial and error. The type of -filter is actually string , not scriptbloock, so it has to get converted to string first. Maybe try this, but I don’t have that command. Something similar works for get-aduser.
Let me express my gratitude for the effort to answer my questions.
I have read Read Me Before Posting! You’ll be Glad You Did!. I assume Olaf that you point to the fact that my code was not preformatted. My bad I was looking this option in the menu and did not realised that it is the option in the Paragraph drop-down list.
Anyhow thank you so much for the link Olaf, this was right direction. js you are also right.
I have found two syntaxes to be the most reliable. As mentioned before, do not use script block notation {} for these filters. The online documentation is incorrect in showing examples of doing so. They are strings and are interpreted as strings.
# Works for cases when $test value does not contain ' (single quote)
# This syntax supports sub-expressions
Get-Mailbox -Filter "EmailAddresses -like '$test'"
# Works for all values that I've considered
# Only supports simple variable references
Get-Mailbox -Filter 'EmailAddresses -like $test'
I’d also like to add that it can be confusing especially for those new to powershell who learn variables expand in “” but not ‘’. That’s not the case for this filter. Also you can add many additional conditions.