Naming and creating variables
Variables in PowerShell are preceded by the dollar symbol ($
), for example:
$MyVariable
Values are assigned to variables using the assignment operator, =:
$MyVariable = 'Hello World'
It is possible to assign the same value to several variables in one statement. For example, this creates two variables, first
and second
, both with a value of 0
:
$first = $second = 0
The name of a variable may contain numbers, letters, underscores, and question marks. For example, each of the following is a valid name:
$123
$x
$my_variable
$variable
$varIABle
$Path_To_File
The following are invalid names, each includes a character outside of the set above:
$a-b
$variable!
$a{b}c
Variables are frequently written in either camel case or Pascal case. For example:
$myVariable
is camel case.$MyVariable
is Pascal case.
PowerShell does not enforce a naming convention, nor does it consistently...