-
-
Save developerprofiles/eb5b0ccdc9706e0f593378b5c3da0381 to your computer and use it in GitHub Desktop.
Pass function as argument in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reverse-String { | |
param( | |
[string]$instr | |
) | |
$chars = $instr.ToCharArray() | |
[array]::Reverse($chars) | |
$chars -join "" | |
} | |
Invoke-Command { | |
param($string,$func) | |
[scriptblock]::Create($func).Invoke($string) | |
} -ArgumentList "abc",${function:Reverse-String} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment