Use of Variables
When working with Windows PowerShell, the default is that you don't need to declare variables prior to use; the variable is declared when you use it to hold data. All variable names must be preceded with a dollar sign. There are a number of special variables in Windows PowerShell. These variables are created automatically and each has a special meaning. Table 2-2 lists the special variables and their associated meanings.
Table 2-2. Use of Special Variables
Name | Use |
|---|---|
$^ | Contains the first token of the last line input into the shell. |
$$ | Contains the last token of the last line input into the shell. |
$_ | The current pipeline object; used in script blocks, filters, Where-Object, ForEach-Object, and switch. |
$? | Contains the success/fail status of ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access