Skip to content

Instantly share code, notes, and snippets.

@developerprofiles
Forked from IISResetMe/passfunc.ps1
Created September 15, 2021 07:43
Show Gist options
  • Save developerprofiles/eb5b0ccdc9706e0f593378b5c3da0381 to your computer and use it in GitHub Desktop.
Save developerprofiles/eb5b0ccdc9706e0f593378b5c3da0381 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