Other operators
PowerShell has a wide variety of operators, a few of which do not easily fall into a specific category:
- Call:
&
- Comma:
,
- Format:
-f
- Increment and decrement:
++
and--
- Join:
-join
Each of these operators is in common use. The call operator can run a command based on a string, to the format operator which can be used to build up complex strings, and so on.
Call
The call operator (&
) is used to execute a string or script block. The call operator is particularly useful when running commands (executables or scripts) that have spaces in the path. The call operator is also useful if the command name changes based on circumstances, for example, the operating system running a command.
The following example runs pwsh.exe
using a full path held in a string:
& 'C:\Program Files\PowerShell\7\pwsh.exe'
The path to pwsh.exe
is normally in the PATH
environment variable, using the full path...