Powershell: Function Pointer


Powershell provides also the ability to use function pointers such as C or C++.

Define your functions

function A([string]$Parameter1,[int]$Parameter2)

   write-host "Function: A" "Parameter 1:" $Parameter1 "Parameter 2:" $Parameter2
function B([string]$Parameter1,[int]$Parameter2)
   write-host "Function: B" "Parameter 1:" $Parameter1 "Parameter 2:" $Parameter2

Assign the functions to a variable and call the function

$pFunction=(Get-Item "function:A").ScriptBlock
$pFunction=(Get-Item "function:B").ScriptBlock

That’s it 🙂


Time limit is exhausted. Please reload CAPTCHA.

Original Theme by Schiy · Powered by WordPress