PowerShell has a wide variety of operators, a few of which do not easily fall into a specific category, as discussed shortly, including the following:
- Call:
&
- Comma:
,
- Format:
-f
- Increment and decrement:
++
and--
- Join:
-join
The call operator is used to execute a string or script block. For example, the call operator may be used to execute the ipconfig
command:
$command = 'ipconfig'
& $command
Or it may be used to execute a script block:
$scriptBlock = { Write-Host 'Hello world' }
& $scriptBlock
The call
operator accepts a list of arguments that can be passed to the command. For example, the displaydns
parameter can be passed into the ipconfig
command:
& 'ipconfig' '/displaydns'
The comma operator may be used to separate elements in an array, for example:
$array = 1, 2, 3, 4
If the comma operator is used before a single value, it creates an array containing one element:
$array = ,1