Search code examples
functionpowershellpowershell-2.0

Invoking Function in PowerShell via String


I'm trying to Invoke a Powershell function "dynamically" using a string. Example

$functionToInvoke = "MyFunctionName";

Invoke-Function $functionToInvoke $arg1 $arg2  #  <- what I would like to do

Is there any way to achieve this with PowerShell 2.0 ?


Solution

  • You can do this:

     &"MyFunctionName" $arg1 $arg2