Invocation
CAUTION
Always be careful to run an external script or input script content.
Call Operator
Call operator &
can be used for invoking one of the following:
- Command without any option.
- A
.ps1
script file - External executable
- Script block
NOTE
&
is awared of the context of current session, it does not start a new process when executing.
ps1
& 'gps'
& 'gps pwsh' # extra option not allowed
& 'gps' pwsh # pass option after command name instead
& 'gps' -Name pwsh # pass option after command name instead
& 'path/to/script.ps1' # may add some option...
& { param($a, $b) $a, $b } 1, 2
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Invoke-Expression
Invoke-Expression
used for executing any script content represented as a string.
ps1
Invoke-Expression 'gps pwsh'
'gps pwsh' | iex
1
2
2