1

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 ?

Tony
  • 8,681
  • 7
  • 36
  • 55
  • 1
    You don't need `Invoke-Command`, simply use the call operator `&` like this: `& $test argumentForPath`. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3#call-operator- – zett42 Dec 03 '22 at 22:49

1 Answers1

0

To invoke script blocks with parameters (locally, in the context of the current user):

$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' 
mklement0
  • 382,024
  • 64
  • 607
  • 775