Q:

Powershell Expanding Variables in Where $_ -like $Var

Ok I am trying to do something like the following:
Simplified Example:
$Var = "MyProduct*MyProduct"
$List += "MyProduct 11 MyProduct"
$List += "YourProduct 11 YourProduct"
$List += "SomethingElse"
$NewVar = $List | Where {$_ -like "$Var"}

I want the "*" in $Var to be expanded then check if it is -like "$_" so that it will recognize there is a wildcard in the var and get results based on that.. Is there any way to do that?

A:

$list is not an array, each time you add to it you are actually concatenating to it. You can start with a single item array, using the unary comma operator (this is just one way to do it), now each addition will add a new array item:
PS> $List = ,"MyProduct 11 MyProduct"
PS> $List += "YourProduct 11 YourProduct"
PS> $List += "SomethingElse"
PS> $list
MyProduct 11 MyProduct
YourProduct 11 YourProduct
SomethingElse

PS> $List -like $var
MyProduct 11 MyProduct

