Get-Variable / Set-Variable and Test-Path attempt to support wildcarding on the name supplied. They all fail if you pass them a name as follows: a[b-a] because they see [b-a] as a broken wildcard range.
This bites psake when it attempts to push variables into child scopes for task execution, and apply supplied -properties arguments over the top of those in the script. Psake passes the name of the properties literally to Test-Path, which causes the error:
You can replicate this as follows:
.\psake.ps1 -file:AnyPsakeFileItDoesntMatter -properties:@{'a[b-a]'=1}
Or as follows (which is what psake ends up doing as a result):
Test-Path 'Variable:\a[b-a]'
I've raised a (Connect article for this)[https://connect.microsoft.com/PowerShell/feedback/details/926973/set-variable-throws-the-specified-wildcard-pattern-is-not-valid-if-variable-name-contains-or-chars-in-some-cases], because I feel existing PowerShell behavior is actually broken. However, there is a workaround that I think psake should implement till they fix it :-) which is to escape the names passed to set-variable / get-variable / test-path by prefixing the square brackets with backticks as follows (if I can get the markdown right :)
$safeKey = ($.Key -replace '[','[') -replace ']',']';
Set-Variable -Name:$safeKey -Value:$.Value
This bit me with OctopusDeploy, because (in my case) it passes in properties of exactly that form which - just because of my role names - end up having backwards ranges within them. If interested, I blogged about this
Get-Variable / Set-Variable and Test-Path attempt to support wildcarding on the name supplied. They all fail if you pass them a name as follows: a[b-a] because they see [b-a] as a broken wildcard range.
This bites psake when it attempts to push variables into child scopes for task execution, and apply supplied -properties arguments over the top of those in the script. Psake passes the name of the properties literally to Test-Path, which causes the error:
You can replicate this as follows:
Or as follows (which is what psake ends up doing as a result):
I've raised a (Connect article for this)[https://connect.microsoft.com/PowerShell/feedback/details/926973/set-variable-throws-the-specified-wildcard-pattern-is-not-valid-if-variable-name-contains-or-chars-in-some-cases], because I feel existing PowerShell behavior is actually broken. However, there is a workaround that I think psake should implement till they fix it :-) which is to escape the names passed to set-variable / get-variable / test-path by prefixing the square brackets with backticks as follows (if I can get the markdown right :)
This bit me with OctopusDeploy, because (in my case) it passes in properties of exactly that form which - just because of my role names - end up having backwards ranges within them. If interested, I blogged about this