By the About Quoting Rules help topic (Get-Help about_quoting_rules -Full
), use single or double quotes as follows:
. cmd /c 'For /L %i in (2,2,5) DO @(Echo %i)'
2
4
or
$step=2
. cmd /c "For /L %i in (2,$step,5) DO @(Echo %i)"
2
4
However, by the About Parsing help topic (Get-Help about_parsing -Full
), there are more ways to achieve this:
- by ad hoc escaping some PowerShell-poisonous symbols e.g.
()
parentheses, $
Dollar Sign, @
Commercial At etc., see also Get-Help about_Escape_Characters
(online version not found). In Windows PowerShell, the escape character is the `
backtick, also called the grave accent (codepoint U+0060
, ASCII 96
).:
cmd /c For /L %i in `(2,1,4`) DO `@`(Echo %i`)
2
3
4
- by using the stop-parsing symbol (
--%
)` (introduced in PowerShell 3.0, directs PowerShell to refrain from interpreting input as PowerShell commands or expressions). This technique is much easier than using escape characters to prevent misinterpretation:
cmd /c --% For /L %i in (2,1,4) DO @(Echo %i)
2
3
4