Parser error when using brackets inside of a subexpression - by Kirk Munro

Status : 


Sign in
to vote
ID 789636 Comments
Status Active Workarounds
Type Bug Repros 1
Opened 6/6/2013 7:38:49 AM
Access Restriction Public


The scenario is simple. You're dynamically building a filter, and you want to add brackets around the items in the filter.  Here are the items:

$filters = @('one','two')

And here's the logic to combine those with brackets and an -and operator:

"($($filters -join ') -and ('))"

If you try to do this in ISE, you get red squiggles due to a parser error.  If you try to do this in the native console, PowerShell thinks you're not done and uses line continuance to continue the command.  Yet it is a complete, valid command.

This works:
$($filters -join ') -and (')

Yet dropping that inside of double-quotes results in an error due to a parser bug.

Here are the most simplified examples I could come up with that cause this bug to show itself:

"$($filters -join '(')"
"$($filters -join ')')"
Sign in to post a comment.