Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active September 15, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IISResetMe/75a16fe7dc40934d3fb4 to your computer and use it in GitHub Desktop.
Save IISResetMe/75a16fe7dc40934d3fb4 to your computer and use it in GitHub Desktop.
Pass function as argument in PowerShell
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