--%
will prevent the remainder of a statement from being parsed by PowerShell. Jose Barreto's Blog on TechNet has a very relevant entry to this problem. Along with providing example usage of --%
, there are others, such as cmd /c
, which may be more helpful for solving your issue since PowerShell not resolving variables after --%
seems problematic for your use case.
--%
is new in PowerShell version 3.
Some example usage from the linked blog:
PS C:\> ICACLS.EXE --% C:\TEST /GRANT USERS:(F)
processed file: C:\TEST
Successfully processed 1 files; Failed processing 0 files
PS C:\> ICACLS.EXE C:\TEST --% /GRANT USERS:(F)
processed file: C:\TEST
Successfully processed 1 files; Failed processing 0 files
As I mentioned above, you would probably be better off trying a solution where you can use PowerShell variables. & " "
or cmd /c " "
will both resolve variables and may be a good place to start.
cmd /c "path/plink.exe $Hostname -l $Username -pw $Password $Command"
I was digging around in the PowerShell Language Specification for something unrelated and found some documentation for --%
. I'll post it here in the hopes that it will be easier to find online for future users:
Excerpt from 8.2 "Pipeline statements"
An argument of --% indicates that all arguments following it are to be
passed with minimal parsing and processing. This argument is called
the verbatim parameter. Arguments after the verbatim parameter are not
PowerShell expressions even if they are syntactically valid PowerShell
expressions.
Windows PowerShell: If the command type is Application, the parameter
--% is not passed to the command. The arguments after --% have any environment variables (strings surrounded by %) expanded. For example:
echoargs.exe --% "%path%" # %path% is replaced with the value
$env:path