How can I escape a PowerShell reserved word? How can I escape a PowerShell reserved word? powershell powershell

How can I escape a PowerShell reserved word?


This have nothing to do with filter being reserved word in PowerShell. The problem in how PowerShell pass parameters to native application. Your command line will be passed as:

OpenCover.Console.exe -output:Coverage.xml -register:user "-filter:"+[*]* -[*]*.Test*"" -target:nunit-console.exe "-targetargs:"Test.dll /config:Release /noshadow /nologo /labels""

Some extra quotes, added by PowerShell, cause that wrong command line will be passed to native application.

First thing you can try, is to change command line to following:

OpenCover.Console.exe -output:Coverage.xml -register:user "-filter:+[*]* -[*]*.Test*" -target:nunit-console.exe "-targetargs:Test.dll /config:Release /noshadow /nologo /labels"

In that case, no extra quotes will be added by PowerShell, and possible that OpenCover.Console.exe can recognize your command.

If that does not help, than you could use Start-Process cmdlet, it never add any extra qoutes:

Start-Process OpenCover.Console.exe '-output:Coverage.xml -register:user -filter:"+[*]* -[*]*.Test*" -target:nunit-console.exe -targetargs:"Test.dll /config:Release /noshadow /nologo /labels"' -NoNewWindow -Wait


Have you tried reading the "about_Escape_Characters" section on PowerShell technet? https://technet.microsoft.com/en-us/library/hh847755.aspx

STOP-PARSING SYMBOL

When calling other programs, you can use the stop-parsing symbol (--%) to prevent Windows PowerShell from generating errors or misinterpreting program arguments. The stop-parsing symbol is an alternative to using escape characters in program calls. It is introduced in Windows PowerShell 3.0.

For example, the following command uses the stop-parsing symbol in an Icacls command:

icacls X:\VMS --% /grant Dom\HVAdmin:(CI)(OI)F

For more information about the stop-parsing symbol, see about_Parsing.