Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Dynamic Where-Object Filter

$
0
0

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.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>