Escaping splatted variables in Powershell Invoke-Expression Escaping splatted variables in Powershell Invoke-Expression powershell powershell

Escaping splatted variables in Powershell Invoke-Expression


bcompare '@static.diff'

If in doubt, put it into a string :-)

PS Home:\> args '@static.diff'argv[0] = "C:\Users\Joey\Batches\args.cmd"argv[1] = @static.diff


You need to double escape, because you are going through two levels of interpretation. Only one ` will not work because it get parsed during the string creation.

Invoke-Expression "bcompare ``@static.diff"

Or as Joey said.

Invoke-Expression "bcompare '@static.diff'"


When I ran into the same problem, I used a backtick to make the @-sign interpreted literally. I wanted to use double-quotes for variable handling as well:

Invoke-Expression "& bcompare `@$compareCommands $file1 $file2"