Last active
August 29, 2015 14:19
Higher-order PowerShell function
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
# Create a function that accepts a function that takes arguments | |
Function Test ([scriptblock]$code, $name) { | |
& $code "$name+$name" | % { | |
New-Object PSObject -Property @{ | |
Name = $name | |
Prop = "**$_**" | |
} | |
} | |
} | |
# Create a function to call | |
Function Set-Lower ([string]$x) { | |
$x.ToLowerInvariant() | |
} | |
# Create a suitable script block to wrap the function and take a parameter | |
$b = [scriptblock] { param([string]$Target = "PARAM") Set-Lower $Target } | |
# Invoke the Test function passing it a scriptblock and argument | |
Test $b Junku |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment