I have a script block
$test = {
param(
$path )
other stuff here...}
I assume I need to use Invoke-Command -ScriptBlock $test
but how do I pass what the $path param should be ?
I have a script block
$test = {
param(
$path )
other stuff here...}
I assume I need to use Invoke-Command -ScriptBlock $test
but how do I pass what the $path param should be ?
To invoke script blocks with parameters (locally, in the context of the current user):
do not use Invoke-Command
(see this answer for more information).
use &
, the call operator.
$test = {
param($path)
"[$path]" # diagnostic output.
}
# Note:
# * Target parameter -path is *positionally implied*
# * To be explicit, call: & $test -path 'my -path value'
& $test 'my -path value'