Given these powershell functions where foo takes a scriptblock as parameter:
function bar($name)
{
"Hello World $name"
}
function foo([scriptblock]$fun={})
{
&$fun "Bart"
}
Is it possible to specify the function bar as default for $fun instead of {} in function foo?
Yes, it is possible. For example, this way works for passing a function in:
In your case it prints
Thus, in order to use it as the default parameter:
Now just calling
gets the same result.