I'm trying to use a dynamic where-object filter by building it and assigning it to a variable and then using that variable, something like the following:
$filter = "`$_.thing -match `"criteria`""
get-thing $things | ? {$filter}
But this fails to match, whereas the following matches:
get-thing $things | ? {$_.thing -match "criteria"}
What am I missing?
When I look at $filter after the assignment above, it looks exactly like what's in the curly brackets in the second get-thing call.
I want to be able to do this because there may be multiple criteria and I need to dynamically add -or clauses. If there's a better way, please let me know what that is.
Thanks.