Vous êtes sur la page 1sur 3



Describes how Windows PowerShell parses command

When you enter a command at the command prompt,
Windows PowerShell
breaks the command text into a series of segmen
ts called tokens
and then determines how to interpret each one.
For example, Windows
PowerShell breaks the following command into tw
o tokens, "Write-Host"
and "book", and interprets each token separatel

Write-Host book

When processing a command, the Windows PowerShe

ll parser operates
in expression mode or in argument mode:

- In expression mode, character string valu

es must be contained in
quotation marks. Numbers not enclosed in
quotation marks are treated
as numerical values (rather than as a ser
ies of characters).

- In argument mode, each value is treated a

s an expandable string
unless it begins with one of the followin
g special characters: dollar
sign ($), at sign (@), single quotation m
ark ('), double quotation
mark ("), or an opening parenthesis (().
If preceded by one of these characters, the val
ue is treated as a value

The following table provides several examples o

f commands processed in
expression mode and argument mode and the resul
ts produced by those

Example Mode Result

------------------ ---------- ---------------
2+2 Expression 4 (integer)
Write-Output 2+2 Argument "2+2" (string)
Write-Output (2+2) Expression 4 (integer)
$a = 2+2 Expression $a = 4 (integer
Write-Output $a Expression 4 (integer)
Write-Output $a/H Argument "4/H" (string)

Every token can be interpreted as some kind of

object type, such
as Boolean or string. Windows PowerShell attemp
ts to determine the
object type from the expression. The object typ
e depends on the
type of parameter a command expects and on whet
her Windows PowerShell
knows how to convert the argument to the correc
t type. The
following table shows several examples of the t
ypes assigned to
values returned by the expressions.

Example Mode Result

------------------ ---------- ---------------
Write-Output !1 argument "!1" (string)
Write-Output (!1) expression False (Boolean)

Write-Output (2) expression 2 (integer)