Last active
September 15, 2021 07:43
-
-
Save IISResetMe/75a16fe7dc40934d3fb4 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